SQL Serverのデータ型で.NET Frameworkの型をマッピング
SQL Serverのデータ型を.netでマッピングする際の対応表をメモ。
SQL Server データベース エンジンの型 | .NET Framework 型 | SqlDbType 列挙 | SqlDataReader SqlTypes の型指定されたアクセサー |
---|---|---|---|
bigint | Int64 | BigInt | GetSqlInt64 |
バイナリ | Byte[] | VarBinary | GetSqlBinary |
ビット | Boolean | Bit | GetSqlBoolean |
char | String Char[] | Char | GetSqlString |
Date(SQL Server 2008 以降) | DateTime | Date | GetSqlDateTime |
datetime | DateTime | DateTime | GetSqlDateTime |
datetime2(SQL Server 2008 以降) | DateTime | DateTime2 | None |
datetimeoffset(SQL Server 2008 以降) | DateTimeOffset | DateTimeOffset | None |
decimal | Decimal (10 進数型) | Decimal | GetSqlDecimal |
FILESTREAM 属性 (varbinary(max)) | Byte[] | VarBinary | GetSqlBytes |
float | Double (倍精度浮動小数点型) | Float | GetSqlDouble |
イメージ | Byte[] | Binary | GetSqlBinary |
int | Int32 | Int | GetSqlInt32 |
money | Decimal (10 進数型) | Money | GetSqlMoney |
nchar | String Char[] | NChar | GetSqlString |
ntext | String Char[] | NText | GetSqlString |
数値 | Decimal (10 進数型) | Decimal | GetSqlDecimal |
nvarchar | String Char[] | NVarChar | GetSqlString |
実数 | Single | Real | GetSqlSingle |
rowversion | Byte[] | Timestamp | GetSqlBinary |
smalldatetime | DateTime | DateTime | GetSqlDateTime |
smallint | Int16 | SmallInt | GetSqlInt16 |
smallmoney | Decimal (10 進数型) | SmallMoney | GetSqlMoney |
sql_variant | Object* | Variant | GetSqlValue* |
テキスト | String Char[] | Text | GetSqlString |
Time (SQL Server 2008 以降) | TimeSpan | Time | None |
タイムスタンプ | Byte[] | Timestamp | GetSqlBinary |
tinyint | Byte | TinyInt | GetSqlByte |
uniqueidentifier | Guid | UniqueIdentifier | GetSqlGuid |
varbinary | Byte[] | VarBinary | GetSqlBinary |
varchar | String Char[] | VarChar | GetSqlString |
xml | Xml | Xml | GetSqlXml |
SQL Server データベース エンジンの型 | DbType 列挙 | SqlDataReader DbType の型指定されたアクセサー |
---|---|---|
bigint | Int64 | GetInt64 |
バイナリ | Binary | GetBytes |
ビット | Boolean | GetBoolean |
char | AnsiStringFixedLength,String | GetString GetChars |
Date(SQL Server 2008 以降) | Date | GetDateTime |
datetime | DateTime | GetDateTime |
datetime2(SQL Server 2008 以降) | DateTime2 | GetDateTime |
datetimeoffset(SQL Server 2008 以降) | DateTimeOffset | GetDateTimeOffset |
decimal | Decimal | GetDecimal |
FILESTREAM 属性 (varbinary(max)) | Binary | GetBytes |
float | Double | GetDouble |
イメージ | Binary | GetBytes |
int | Int32 | GetInt32 |
money | Decimal | GetDecimal |
nchar | StringFixedLength | GetStringGetChars |
ntext | String | GetStringGetChars |
数値 | Decimal | GetDecimal |
nvarchar | String | GetStringGetChars |
実数 | Single | GetFloat |
rowversion | Binary | GetBytes |
smalldatetime | DateTime | GetDateTime |
smallint | Int16 | GetInt16 |
smallmoney | Decimal | GetDecimal |
sql_variant | Object | GetValue* |
テキスト | String | GetStringGetChars |
Time (SQL Server 2008 以降) | Time | GetDateTime |
タイムスタンプ | Binary | GetBytes |
tinyint | Byte | GetByte |
uniqueidentifier | Guid | GetGuid |
varbinary | Binary | GetBytes |
varchar | AnsiString,String | GetStringGetChars |
xml | Xml | None |