您的位置:首页 > 数据库

如何判断数据库数据类型 ad0

2007-03-31 19:27 337 查看
从数据库读数据到CELL时,用D方法只能读入数值型,用S方法只能读入字符型。请问如何判断字段的数据类型(比如:数值、文本、货币、逻辑型等…… ),谢谢。



在ADO中可以取得字段的类型,Fields(i).Type

COleVariant类

COleVariant 类通逢装了 VARIANT 结构。实际的数据就在 VARIANT 结构中。
使用 COleVariant 的两个操作
operator LPCVARIANT
Converts a COleVariant value into an LPCVARIANT.
operator LPVARIANT
Converts a COleVariant object into an LPVARIANT.
可以得到 VARIANT 结构。其区别是,前者是个拷贝操作,将 VARIANT 结构的内容拷贝到目标中去,后者仅仅返回
VARIANT 结构的指针。不管那种情况,现在我们都能访问到 VARIANT 所包含的数据了。余下的问题是如何解释数
据内容。
VARIANT 结构包含两部分。其一是 VARTYPE 型的成员变量vt;其二是个联合类型,这个联合包含了VC常用的几乎所有类型。因为联合用的是相同的存储空间,因此对联合的内容的解释依赖于 vt。
例如,
若 vt 的值是 VT_UI2, 说明该联合被解释为short int. 并使用成员变量名 iVal。
若 vt 的的值是 VT_BSTR,说明该联合被解释为 BSTR 类型。并使用成员变量名 bstrVal。
若 vt 的的值是 VT_BSTR|VT_BYREF,说明该联合被解释为BSTR 型指针。并使用成员变量名 pbstrVal。
(其他详见 VARIANT 的联机帮助)
*********************************
若从数据库返回的是简单类型,如 short, long, 等,则直接引用既可。(主持人注:COleVariant类重载了“=”操作符,所以常用类型可以直接转换)若返回的是字符串类型,则有可能是 bstrVal 或pbstrVal。依赖于数据库服务程序。 BSTR 实际上就是个unicode 字符串,CString 的构造函数和赋值操作都能直接识别这一类型。

Type Property

Indicates the operational type or data type of a Parameter, Field, or Property object.

Settings and Return Values

Sets or returns a DataTypeEnum value.

Remarks

For Parameter objects, the Type property is read/write. For new Field objects that have been appended to the Fields collection of a Record, Type is read/write only after the Value property for the Field has been specified and the data provider has successfully added the new Field by calling the Update method of the Fields collection.

For all other objects, the Type property is read-only.

DataTypeEnum

Specifies the data type of a Field, Parameter, or Property. The corresponding OLE DB type indicator is shown in parentheses in the description column of the following table. For more information about OLE DB data types, see Chapter 13: Data Types in OLE DB and Appendix A: Data Types of the OLE DB Programmer's Reference.

ConstantValueDescription
AdArray
(Does not apply to ADOX.)
0x2000A flag value, always combined with another data type constant, that indicates an array of that other data type.
adBigInt20Indicates an eight-byte signed integer (DBTYPE_I8).
adBinary128Indicates a binary value (DBTYPE_BYTES).
adBoolean11Indicates a boolean value (DBTYPE_BOOL).
adBSTR8Indicates a null-terminated character string (Unicode) (DBTYPE_BSTR).
adChapter136Indicates a four-byte chapter value that identifies rows in a child rowset (DBTYPE_HCHAPTER).
adChar129Indicates a string value (DBTYPE_STR).
adCurrency6Indicates 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.
adDate7Indicates 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.
adDBDate133Indicates a date value (yyyymmdd) (DBTYPE_DBDATE).
adDBTime134Indicates a time value (hhmmss) (DBTYPE_DBTIME).
adDBTimeStamp135Indicates a date/time stamp (yyyymmddhhmmss plus a fraction in billionths) (DBTYPE_DBTIMESTAMP).
adDecimal14Indicates an exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL).
adDouble5Indicates a double-precision floating-point value (DBTYPE_R8).
adEmpty0Specifies no value (DBTYPE_EMPTY).
adError10Indicates a 32-bit error code (DBTYPE_ERROR).
adFileTime64Indicates a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (DBTYPE_FILETIME).
adGUID72Indicates a globally unique identifier (GUID) (DBTYPE_GUID).
adIDispatch9Indicates 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.

adInteger3Indicates a four-byte signed integer (DBTYPE_I4).
adIUnknown13Indicates 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.

adLongVarBinary205Indicates a long binary value.
adLongVarChar201Indicates a long string value.
adLongVarWChar203Indicates a long null-terminated Unicode string value.
adNumeric131Indicates an exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC).
adPropVariant138Indicates an Automation PROPVARIANT (DBTYPE_PROP_VARIANT).
adSingle4Indicates a single-precision floating-point value (DBTYPE_R4).
adSmallInt2Indicates a two-byte signed integer (DBTYPE_I2).
adTinyInt16Indicates a one-byte signed integer (DBTYPE_I1).
adUnsignedBigInt21Indicates an eight-byte unsigned integer (DBTYPE_UI8).
adUnsignedInt19Indicates a four-byte unsigned integer (DBTYPE_UI4).
adUnsignedSmallInt18Indicates a two-byte unsigned integer (DBTYPE_UI2).
adUnsignedTinyInt17Indicates a one-byte unsigned integer (DBTYPE_UI1).
adUserDefined132Indicates a user-defined variable (DBTYPE_UDT).
adVarBinary204Indicates a binary value.
adVarChar200Indicates a string value.
adVariant12Indicates an Automation Variant (DBTYPE_VARIANT).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.

adVarNumeric139Indicates a numeric value.
adVarWChar202Indicates a null-terminated Unicode character string.
adWChar130Indicates a null-terminated Unicode character string (DBTYPE_WSTR).
ADO/WFC Equivalent
Package: com.ms.wfc.data

Constant
AdoEnums.DataType.ARRAY
AdoEnums.DataType.BIGINT
AdoEnums.DataType.BINARY
AdoEnums.DataType.BOOLEAN
AdoEnums.DataType.BSTR
AdoEnums.DataType.CHAPTER
AdoEnums.DataType.CHAR
AdoEnums.DataType.CURRENCY
AdoEnums.DataType.DATE
AdoEnums.DataType.DBDATE
AdoEnums.DataType.DBTIME
AdoEnums.DataType.DBTIMESTAMP
AdoEnums.DataType.DECIMAL
AdoEnums.DataType.DOUBLE
AdoEnums.DataType.EMPTY
AdoEnums.DataType.ERROR
AdoEnums.DataType.FILETIME
AdoEnums.DataType.GUID
AdoEnums.DataType.IDISPATCH
AdoEnums.DataType.INTEGER
AdoEnums.DataType.IUNKNOWN
AdoEnums.DataType.LONGVARBINARY
AdoEnums.DataType.LONGVARCHAR
AdoEnums.DataType.LONGVARWCHAR
AdoEnums.DataType.NUMERIC
AdoEnums.DataType.PROPVARIANT
AdoEnums.DataType.SINGLE
AdoEnums.DataType.SMALLINT
AdoEnums.DataType.TINYINT
AdoEnums.DataType.UNSIGNEDBIGINT
AdoEnums.DataType.UNSIGNEDINT
AdoEnums.DataType.UNSIGNEDSMALLINT
AdoEnums.DataType.UNSIGNEDTINYINT
AdoEnums.DataType.USERDEFINED
AdoEnums.DataType.VARBINARY
AdoEnums.DataType.VARCHAR
AdoEnums.DataType.VARIANT
AdoEnums.DataType.VARNUMERIC
AdoEnums.DataType.VARWCHAR
AdoEnums.DataType.WCHAR

See Also

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: