问题是,我现在要做的是 C# 转 SQL Server 类型。但是 C# 相对 SQL Server 是多对一的关系,这时需要考虑多个 SQL Server 类型之间有无包含的关系。他们之间是否可以在程序中始终指定一个类型的值来对其它相关类型的值进行读写?比如:byte[] 对应三个类型,image,timestamp 和 varbinary。能否用varbinary来直接存取其他两个类型的字段的值?在经过测试之后发现可以。而且关系如下表,其中 Priority 就是指当指定的 C# 类型对应多个 SQL Server 类型的时候,代码中所使用的SqlDbType类型。
两者的关系对应如下:
SQL Server
C#
Priority
Bit
bool
TinyInt
byte
Image
byte[]
Timestamp
byte[]
Varbinary
byte[]
★
DateTime
DateTime
★
SmallDateTime
DateTime
Decimal
decimal
★
Money
decimal
SmallMoney
decimal
Float
double
Real
float
Int
int
BigInt
long
Binary
object
SmallInt
short
Char
string
NChar
string
NText
string
NVarchar
string
★
Text
string
Varchar
string
Xml
string
UniqueIdentifier
Guid
最新评论