`
vtrtbb
  • 浏览: 353452 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

 
阅读更多
SQL Server类型 C#类型
bit bool
tinyint byte
smallint short
int int
bigint long
real float
float double
money decimal
datetime DateTime
char string
varchar string
nchar string
nvarchar string
text string
ntext string
image byte[]
binary byte[]
uniqueidentifier Guid

 

 

     // 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;

            }

        } 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics