sql-C#-类型对应
生活随笔
收集整理的這篇文章主要介紹了
sql-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;}} 復制內容到剪貼板 代碼: // sql server數據類型(如:varchar) // 轉換為SqlDbType類型 public static SqlDbType SqlTypeString2SqlType(string sqlTypeString){SqlDbType dbType = SqlDbType.Variant;//默認為Objectswitch (sqlTypeString){case "int":dbType = SqlDbType.Int;break;case "varchar":dbType = SqlDbType.VarChar;break;case "bit":dbType = SqlDbType.Bit;break;case "datetime":dbType = SqlDbType.DateTime;break;case "decimal":dbType = SqlDbType.Decimal;break;case "float":dbType = SqlDbType.Float;break;case "image":dbType = SqlDbType.Image;break;case "money":dbType = SqlDbType.Money;break;case "ntext":dbType = SqlDbType.NText;break;case "nvarchar":dbType = SqlDbType.NVarChar;break;case "smalldatetime":dbType = SqlDbType.SmallDateTime;break;case "smallint":dbType = SqlDbType.SmallInt;break;case "text":dbType = SqlDbType.Text;break;case "bigint":dbType = SqlDbType.BigInt;break;case "binary":dbType = SqlDbType.Binary;break;case "char":dbType = SqlDbType.Char;break;case "nchar":dbType = SqlDbType.NChar;break;case "numeric":dbType = SqlDbType.Decimal;break;case "real":dbType = SqlDbType.Real;break;case "smallmoney":dbType = SqlDbType.SmallMoney;break;case "sql_variant":dbType = SqlDbType.Variant;break;case "timestamp":dbType = SqlDbType.Timestamp;break;case "tinyint":dbType = SqlDbType.TinyInt;break;case "uniqueidentifier":dbType = SqlDbType.UniqueIdentifier;break;case "varbinary":dbType = SqlDbType.VarBinary;break;case "xml":dbType = SqlDbType.Xml;break;}return dbType;} 復制內容到剪貼板 代碼:// sql server中的數據類型,轉換為C#中的類型類型 public static Type SqlTypeString2CsharpType(string sqlTypeString){SqlDbType dbTpe = SqlTypeString2SqlType(sqlTypeString);return SqlType2CsharpType(dbTpe);}// 將sql server中的數據類型,轉化為C#中的類型的字符串 public static string SqlTypeString2CsharpTypeString(string sqlTypeString){Type type = SqlTypeString2CsharpType(sqlTypeString);return type.Name;}
轉載于:https://www.cnblogs.com/lonelyofsoul/p/3655932.html
總結
以上是生活随笔為你收集整理的sql-C#-类型对应的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HFSS阵列天线仿真
- 下一篇: middlegenidenbsp;nbs