由于 Microsoft® SQL Server™ 使用 Transact-SQL 数据类型,而且 OLE 自动化使用 Microsoft Visual Basic® 数据类型,OLE 自动化存储过程必须转换在二者之间传递的数据。
下表描述 SQL Server 到 Visual Basic 的数据类型转换。
| SQL Server 数据类型 | Visual Basic 数据类型 |
|---|---|
| char、varchar、text、nvarchar、ntext | 字符串 |
| decimal、numeric | 字符串 |
| bit | 布尔型 |
| binary、varbinary、image | 一维 Byte() 数组 |
| int | Long |
| smallint | 整型 |
| tinyint | Byte |
| float | 双精度 |
| real | 单精度 |
| money、smallmoney | 货币 |
| datetime、smalldatetime | 日期 |
| 所有都设置为 NULL | 设置为 Null 的 Variant |
除 binary、varbinary 和 image 外,所有单个 SQL Server 值都被转换为单个 Visual Basic 值。在 Visual Basic 中这些值被转换为一维 Byte() 数组。此数组的字节范围为 Byte(0 To length–1),其中,length 为 SQL Server 的 binary、varbinary 或 image 值中的字节数。
以下为 Visual Basic 到 SQL Server 数据类型转换。
| Visual Basic 数据类型 | SQL Server 数据类型 |
|---|---|
| Long、整型、Byte、布尔值、对象 | int |
| 双精度、单精度 | float |
| 货币 | money |
| 日期 | datetime |
| 小于或等于 4000 个字符的字符串 | varchar/nvarchar |
| 大于 4000 个字符的字符串 | text/ntext |
| 小于或等于 8000 字节的一维 Byte() 数组 | varbinary |
| 大于 8000 字节的一维 Byte() 数组 | image |