如何获取字段的数据类型

younerest 2009-03-03 06:04:32
在MS-SQL中,假如有一个字段为ID,表为Student,想请问一下如何获取ID的数据类型?使用ADO连接数据库.
...全文
314 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
eagerle01 2009-03-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 shakaqrj 的回复:]
按楼上方法
AdArray
(Does not apply to ADOX.) 0x2000 A flag value, always combined with another data type constant, that indicates an array of that other data type.
adBigInt 20 Indicates an eight-byte signed integer (DBTYPE_I8).
adBinary 128 Indicates a binary value (DBTYPE_BYTES).
adBoolean 11 Indicates a boolean value (DBTYPE_BOOL).
adBSTR 8 Indicates a null-terminated character st…
[/Quote]
楼上的也太乱了点!:-)
shakaqrj 2009-03-04
  • 打赏
  • 举报
回复
按楼上方法
AdArray
(Does not apply to ADOX.) 0x2000 A flag value, always combined with another data type constant, that indicates an array of that other data type.
adBigInt 20 Indicates an eight-byte signed integer (DBTYPE_I8).
adBinary 128 Indicates a binary value (DBTYPE_BYTES).
adBoolean 11 Indicates a boolean value (DBTYPE_BOOL).
adBSTR 8 Indicates a null-terminated character string (Unicode) (DBTYPE_BSTR).
adChapter 136 Indicates a four-byte chapter value that identifies rows in a child rowset (DBTYPE_HCHAPTER).
adChar 129 Indicates a string value (DBTYPE_STR).
adCurrency 6 Indicates a currency value (DBTYPE_CY). Currency is a fixed-point number with four digits to the right of the decimal point. It is stored in an eight-byte signed integer scaled by 10,000.
adDate 7 Indicates a date value (DBTYPE_DATE). A date is stored as a double, the whole part of which is the number of days since December 30, 1899, and the fractional part of which is the fraction of a day.
adDBDate 133 Indicates a date value (yyyymmdd) (DBTYPE_DBDATE).
adDBTime 134 Indicates a time value (hhmmss) (DBTYPE_DBTIME).
adDBTimeStamp 135 Indicates a date/time stamp (yyyymmddhhmmss plus a fraction in billionths) (DBTYPE_DBTIMESTAMP).
adDecimal 14 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL).
adDouble 5 Indicates a double-precision floating-point value (DBTYPE_R8).
adEmpty 0 Specifies no value (DBTYPE_EMPTY).
adError 10 Indicates a 32-bit error code (DBTYPE_ERROR).
adFileTime 64 Indicates a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (DBTYPE_FILETIME).
adGUID 72 Indicates a globally unique identifier (GUID) (DBTYPE_GUID).
adIDispatch 9 Indicates a pointer to an IDispatch interface on a COM object (DBTYPE_IDISPATCH).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.

adInteger 3 Indicates a four-byte signed integer (DBTYPE_I4).
adIUnknown 13 Indicates a pointer to an IUnknown interface on a COM object (DBTYPE_IUNKNOWN).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.

adLongVarBinary 205 Indicates a long binary value.
adLongVarChar 201 Indicates a long string value.
adLongVarWChar 203 Indicates a long null-terminated Unicode string value.
adNumeric 131 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC).
adPropVariant 138 Indicates an Automation PROPVARIANT (DBTYPE_PROP_VARIANT).
adSingle 4 Indicates a single-precision floating-point value (DBTYPE_R4).
adSmallInt 2 Indicates a two-byte signed integer (DBTYPE_I2).
adTinyInt 16 Indicates a one-byte signed integer (DBTYPE_I1).
adUnsignedBigInt 21 Indicates an eight-byte unsigned integer (DBTYPE_UI8).
adUnsignedInt 19 Indicates a four-byte unsigned integer (DBTYPE_UI4).
adUnsignedSmallInt 18 Indicates a two-byte unsigned integer (DBTYPE_UI2).
adUnsignedTinyInt 17 Indicates a one-byte unsigned integer (DBTYPE_UI1).
adUserDefined 132 Indicates a user-defined variable (DBTYPE_UDT).
adVarBinary 204 Indicates a binary value.
adVarChar 200 Indicates a string value.
adVariant 12 Indicates an Automation Variant (DBTYPE_VARIANT).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.

adVarNumeric 139 Indicates a numeric value.
adVarWChar 202 Indicates a null-terminated Unicode character string.
adWChar 130 Indicates a null-terminated Unicode character string (DBTYPE_WSTR).
younerest 2009-03-04
  • 打赏
  • 举报
回复
谢谢楼上各位了,之所以想获得字段的数据类型主要是因为想获取一些可以进行计算的字段.昨晚我自己找了这样一个方法:
......

RecordSetPtr pRst;
_variant_t var;

......
while(!pRst->rsEOF)
{
var=pRst->GetCollect("ID");
switch(var.vt)
{
case VT_R4://浮点型
break;
case VT_R8://双精度型
break;
case VT_I4://整型
break;
.
.
.
.
default:
break;
}
}
通过这个方法,功能基本实现了,呵,不过,楼上的方法也会试一下.给分
zaodt 2009-03-03
  • 打赏
  • 举报
回复
第二种方法:

用 ADO 读取也可以

int i = m_pRecordset->GetFields()->GetItem("id")->GetType();

获取到的是一个整形,然后自己匹配了,如下:

switch( i )
{
case 0:
...
break;

case 1:
...
}
zaodt 2009-03-03
  • 打赏
  • 举报
回复
SQL Server 中,在每个数据库中有一些系统表会记录这些信息,这个表是:

syscolumns

详情请看它的联机帮助。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧