SQL Server and C # data type correspondence table

Source: Internet
Author: User

Serial number Category Sql server C Sharp Note
1 Integer Bit Boolean True to convert to 1False to 0
2 tinyint Byte C sharp data types are located in the System namespace
3 smallint Int16
4 Int Int32
5 bigint Int64
6 SmallMoney Decimal
7 Money Decimal
8 Numeric Decimal
9 Decimal Decimal
10 Floating point number Float Double
11 Real Single
12 Date and time smalldatetime Datetime
13 Datetime Datetime
14 Timestamp Datetime
15 String Char String
16 Text String
17 varchar String
18 NChar String
19 ntext String
20 nvarchar String
21st Binary data Binary Byte[]
22 varbinary Byte[]
23 Image Byte[]
24 Other uniqueidentifier Guid
25 Variant Object
PS. Originally intended to reprint trackback:http://tb.blog.csdn.net/trackback.aspx?postid=95675 (SQL Server corresponds to the data type in C #, but feels that the author writes it in code, looks less intuitive, and is inconvenient to find. Therefore, the author's article and SQLServer05 's help document make the above table.



trackback:http://tb.blog.csdn.net/trackback.aspx?postid=1288946

<summary>
Comparison of data types in the database with C #
</summary>
<param name= "Type" ></param>
<returns></returns>
private string Changetocsharptype (String type)
{
String Reval=string.empty;
Switch (Type.tolower ())
{
Case "int":
Reval= "Int32";
Break
Case "Text":
Reval= "string";
Break
Case "bigint":
Reval= "Int64";
Break
Case "binary":
Reval= "system.byte[]";
Break
Case "bit":
Reval= "Boolean";
Break
Case "char":
Reval= "string";
Break
Case "datetime":
Reval= "System.DateTime";
Break
Case "decimal":
Reval= "System.Decimal";
Break
Case "float":
Reval= "System.Double";
Break
Case "image":
Reval= "system.byte[]";
Break
Case ' money ':
Reval= "System.Decimal";
Break
Case "NCHAR":
Reval= "string";
Break
Case "ntext":
Reval= "string";
Break
Case "Numeric":
Reval= "System.Decimal";
Break
case "nvarchar":
Reval= "string";
Break
Case "real":
Reval= "System.Single";
Break
Case "smalldatetime":
Reval= "System.DateTime";
Break
Case "smallint":
Reval= "Int16";
Break
Case "SmallMoney":
Reval= "System.Decimal";
Break
Case "Timestamp":
Reval= "System.DateTime";
Break
Case "tinyint":
Reval= "System.Byte";
Break
Case "uniqueidentifier":
Reval= "System.Guid";
Break
Case "varbinary":
Reval= "system.byte[]";
Break
Case "varchar":
Reval= "string";
Break
Case "Variant":
Reval= "Object";
Break
Default
Reval= "string";
Break
}
return Reval;
}

SQL Server and C # data type correspondence table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.