当前位置: 代码迷 >> SQL >> C#中的部类和SQL Server中的类型对应关系
  详细解决方案

C#中的部类和SQL Server中的类型对应关系

热度:60   发布时间:2016-05-05 11:57:23.0
C#中的类型和SQL Server中的类型对应关系
SQL Server类型C#类型
bitbool
tinyintbyte
smallintshort
intint
bigintlong
realfloat
floatdouble
moneydecimal
datetimeDateTime
charstring
varcharstring
ncharstring
nvarcharstring
textstring
ntextstring
imagebyte[]
binarybyte[]
uniqueidentifierGuid

?

?

     // SqlDbType转换为C#数据类型         public static Type SqlType2CsharpType(SqlDbType sqlType)         {             switch (sqlType)             {                    case SqlDbType.BigInt:                      return typeof(Int64);                    case SqlDbType.Binary:                      return typeof(Object);                   case SqlDbType.Bit:                     return typeof(Boolean);                   case SqlDbType.Char:                     return typeof(String);                   case SqlDbType.DateTime:                     return typeof(DateTime);                   case SqlDbType.Decimal:                     return typeof(Decimal);                   case SqlDbType.Float:                     return typeof(Double);                   case SqlDbType.Image:                     return typeof(Object);                   case SqlDbType.Int:                     return typeof(Int32);                   case SqlDbType.Money:                     return typeof(Decimal);                   case SqlDbType.NChar:                     return typeof(String);                   case SqlDbType.NText:                     return typeof(String);                   case SqlDbType.NVarChar:                     return typeof(String);                   case SqlDbType.Real:                     return typeof(Single);                   case SqlDbType.SmallDateTime:                     return typeof(DateTime);                   case SqlDbType.SmallInt:                     return typeof(Int16);                   case SqlDbType.SmallMoney:                     return typeof(Decimal);                   case SqlDbType.Text:                     return typeof(String);                   case SqlDbType.Timestamp:                     return typeof(Object);                   case SqlDbType.TinyInt:                     return typeof(Byte);                   case SqlDbType.Udt://自定义的数据类型                     return typeof(Object);                   case SqlDbType.UniqueIdentifier:                     return typeof(Object);                   case SqlDbType.VarBinary:                     return typeof(Object);                   case SqlDbType.VarChar:                     return typeof(String);                   case SqlDbType.Variant:                     return typeof(Object);                   case SqlDbType.Xml:                     return typeof(Object);                   default:                     return null;            }        } 

?

  相关解决方案