标签:
http://blog.csdn.net/kfhzy/article/details/6020283
http://blog.csdn.net/kfhzy/article/details/6020545
李维的代码,原来链接的是MS SQL,改成ACCESS后,报 类型无效 错误
原因 除了
adDBTimeStamp 这样的 明显不支持的数据类型外,一般的,也有区别,adVarChar 在ACCESS里是adVarWChar
procedure TfrmCreateTable.btnCreateTableClick(Sender: TObject); begin // create table with FCatalog do begin FTable := CoTable.Create; FTable.ParentCatalog := FCatalog; FTable.Name := edtTableName.Text; FTable.Columns.Append(‘ISBN‘, adVarWChar, 20); FTable.Columns.Append(‘BookName‘, adVarWChar, 60); FTable.Columns.Append(‘Publisher‘, adVarWChar, 60); FTable.Columns.Append(‘Author‘, adVarWChar, 10); // FTable.Columns.Append(‘PDT‘, adDBTimeStamp, 8); //MS SQL Server FTable.Columns.Append(‘Price‘, adInteger, 4); // create index FIndex := CoIndex.Create; with FIndex do begin Name := ‘ISBN‘; PrimaryKey := True; Unique := True; Columns.Append(‘ISBN‘, adVarWChar, 20); end; FTable.Indexes.Append(FIndex, EmptyParam); Tables.Append(FTable); end; end;
使用 ADOX 创建 adDBTimeStamp 类型的字段时,会产生“类型无效”的错误提示,产生这种错误的原因是,数据库引擎 Provider 只能接受已知类型的数据类型,下面是可以接受的类型对照表:
ADOX.DataTypeEnum 类型枚举常量 | Value | Jet 3.51 | Jet 4.0 | SQL 7.0 |
---|---|---|---|---|
adBinary | 128 | Yes | Yes | Yes |
adBoolean | 11 | Yes | Yes | Yes |
adChar | 129 | Yes | No | Yes |
adCurrency | 6 | Yes | Yes | Yes |
adDate | 7 | Yes | Yes | No |
adDouble | 5 | Yes | Yes | Yes |
adGUID | 72 | Yes | Yes | Yes |
adInteger | 3 | Yes | Yes | Yes |
adLongVarBinary | 205 | Yes | Yes | Yes |
adLongVarChar | 201 | Yes | No | Yes |
adLongVarWChar | 203 | No | Yes | Yes |
adNumeric | 131 | No | Yes (with info)* | Yes (with info)* |
adSingle | 4 | Yes | Yes | Yes |
adSmallInt | 2 | Yes | Yes | Yes |
adUnsignedTinyInt | 17 | Yes | Yes | Yes |
adVarBinary | 204 | Yes | Yes | Yes |
adVarChar | 200 | Yes | No | Yes |
adVarWChar | 202 | No | Yes | Yes |
adWChar | 130 | No | Yes | Yes |
adDBTimeStamp | 135 | No | No | Yes |
ADO 数据类型
下面的表格列出了 Access、SQL Server 与 Oracle 之间的数据类型映射:
DataType Enum | Value | Access | SQLServer | Oracle |
---|---|---|---|---|
adBigInt | 20 | BigInt (SQL Server 2000 +) | ||
adBinary | 128 | Binary TimeStamp |
Raw * | |
adBoolean | 11 | YesNo | Bit | |
adChar | 129 | Char | Char | |
adCurrency | 6 | Currency | Money SmallMoney |
|
adDate | 7 | Date | DateTime | |
adDBTimeStamp | 135 | DateTime (Access 97 (ODBC)) | DateTime SmallDateTime |
Date |
adDecimal | 14 | Decimal * | ||
adDouble | 5 | Double | Float | Float |
adGUID | 72 | ReplicationID (Access 97 (OLEDB)), (Access 2000 (OLEDB)) | UniqueIdentifier (SQL Server 7.0 +) | |
adIDispatch | 9 | |||
adInteger | 3 | AutoNumber Integer Long |
Identity (SQL Server 6.5) Int |
Int * |
adLongVarBinary | 205 | OLEObject | Image | Long Raw * Blob (Oracle 8.1.x) |
adLongVarChar | 201 | Memo (Access 97) Hyperlink (Access 97) |
Text | Long * Clob (Oracle 8.1.x) |
adLongVarWChar | 203 | Memo (Access 2000 (OLEDB)) Hyperlink (Access 2000 (OLEDB)) |
NText (SQL Server 7.0 +) | NClob (Oracle 8.1.x) |
adNumeric | 131 | Decimal (Access 2000 (OLEDB)) | Decimal Numeric |
Decimal Integer Number SmallInt |
adSingle | 4 | Single | Real | |
adSmallInt | 2 | Integer | SmallInt | |
adUnsignedTinyInt | 17 | Byte | TinyInt | |
adVarBinary | 204 | ReplicationID (Access 97) | VarBinary | |
adVarChar | 200 | Text (Access 97) | VarChar | VarChar |
adVariant | 12 | Sql_Variant (SQL Server 2000 +) | VarChar2 | |
adVarWChar | 202 | Text (Access 2000 (OLEDB)) | NVarChar (SQL Server 7.0 +) | NVarChar2 |
adWChar | 130 | NChar (SQL Server 7.0 +) |
* 在 Oracle 8.0.x 中 - decimal 和 int 等于 number 和 number(10)。
使用 ADOX 将 Table 添加到 Catalog 时报“类型无效”的原因和解决方法
标签:
原文地址:http://www.cnblogs.com/CodeGear/p/4280346.html