SQL Server type corresponds to C # type

Source: Internet
Author: User

SQL Type C # Type BITBOOLTINYINTBYTESMALLINTSHORTINTINTBIGINTLONGREALFLOATFLOATDOUBLEMONEYDECIMALDATETIMEDATETIMECHARSTRINGVARCHARSTRINGN Charstringnvarcharstringtextstringntextstringimagebyte[]binarybyte[]uniqueidentifierguid//sqldbtype conversion to C # Data type 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:// The custom data type is 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);d Efault:return null;}} Code://SQL Server data type (for example: varchar)//Convert to SqlDbType type public static SqlDbType Sqltypestring2sqltype (string sqltypestring) { SqlDbType DbType = sqldbtype.variant;//defaults to Objectswitch (sqltypestring) {case "int":d btype = sqldbtype.int;break;case " varchar ":d btype = sqldbtype.varchar;break;case" bit ":d btype = sqldbtype.bit;break;case" datetime ":d btype = Sqldbtype.datetime;break;case "decimal":d btype = sqldbtype.decimal;break;case "float":d btype = Sqldbtype.float;break Case "image":d btype = sqldbtype.image;Break;case "Money":d btype = sqldbtype.money;break;case "ntext":d btype = sqldbtype.ntext;break;case "nvarchar":d btype = Sqldbtype.nvarchar;break;case "smalldatetime":d btype = sqldbtype.smalldatetime;break;case "smallint":d btype = Sqldbtype.smallint;break;case "text":d btype = sqldbtype.text;break;case "bigint":d btype = sqldbtype.bigint;break; Case "binary":d btype = sqldbtype.binary;break;case "char":d btype = sqldbtype.char;break;case "nchar":d btype = Sqldbtype.nchar;break;case "Numeric":d btype = sqldbtype.decimal;break;case "real":d btype = sqldbtype.real;break;case "SmallMoney":d btype = sqldbtype.smallmoney;break;case "sql_variant":d btype = sqldbtype.variant;break;case "timestamp ":d btype = sqldbtype.timestamp;break;case" tinyint ":d btype = sqldbtype.tinyint;break;case" uniqueidentifier ":d btype = Sqldbtype.uniqueidentifier;break;case "varbinary":d btype = sqldbtype.varbinary;break;case "xml":d btype = Sqldbtype.xml;break;} return dbType;} Code://data type in SQL Server, convert to type type in C # public static type SQLTypestring2csharptype (String sqltypestring) {SqlDbType Dbtpe = Sqltypestring2sqltype (sqltypestring); return Sqltype2csharptype (DBTPE);} Converts a data type in SQL Server to a string of type in C # public static string sqltypestring2csharptypestring (String sqltypestring) {type type = Sqltypestring2csharptype (sqltypestring); return type. Name;}

SQL Server type corresponds to C # type

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.