SQL Server tüüp C# tüüp bitbool tinyintbyte Smallintshort intint Bigintlong realfloat floatdouble moneydekumaal datetimeDateTime charstring varcharstring ncharstring nvarcharstring tekstistring ntextstring imagebyte[] binarybyte[] uniqueidentifierGuid/ SqlDbType转换为C#数据类型 avalik staatiline tüüp SqlType2CsharpType(SqlDbType sqlType)
{ lüliti (sqlType)
{ case SqlDbType.BigInt: tagasipöördumise tüüp (Int64); case SqlDbType.Binary: return typeof(Object); case SqlDbType.Bit: tagasipöördumise tüüp (Boole'i); case SqlDbType.Char: return typeof(String); case SqlDbType.DateTime: return typeof(DateTime); case SqlDbType.Decimal: tagasipöördumise tüüp (kümnendkohta); case SqlDbType.Float: return typeof(Double); case SqlDbType.Image: return typeof(Object); Juhtum SqlDbType.Int: tagasipöördumise tüüp (Int32); case SqlDbType.Money: tagasipöördumise tüüp (kümnendkohta); juhtum SqlDbType.NChar: return typeof(String); case SqlDbType.NText: return typeof(String); case SqlDbType.NVarChar: return typeof(String); case SqlDbType.Real: tagasipöördumise tüüp (üksik); case SqlDbType.SmallDateTime: return typeof(DateTime); case SqlDbType.SmallInt: tagasipöördumise tüüp (Int16); case SqlDbType.SmallMoney: tagasipöördumise tüüp (kümnendkohta); case SqlDbType.Text: return typeof(String); case SqlDbType.Timestamp: return typeof(Object); case SqlDbType.TinyInt: return typeof(Bait); case SqlDbType.Udt:// custom data type 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); vaikimisi: return null;
}
}Kopeeri sisu kirjutusaluseleKood:SQL Serveri andmetüübid (nt varchar) Teisendamine SqlDbType tüübiks avalik staatiline SqlDbType SqlTypeString2SqlType(string sqlTypeString)
{ SqlDbType dbType = SqlDbType.Variant; Vaikimisi on objekt
lüliti (sqlTypeString)
{ Juhtum "int": dbType = SqlDbType.Int; paus; Juhtum "Varchar": dbType = SqlDbType.VarChar; paus; Juhtum "bitt": dbType = SqlDbType.Bit; paus; juhtum "kuupäev": dbType = SqlDbType.DateTime; paus; Juhtum "kümnend": dbType = SqlDbType.Decimal; paus; Korpus "float": dbType = SqlDbType.Float; paus; Juhtum "pilt": dbType = SqlDbType.Pilt; paus; Juhtum "raha": dbType = SqlDbType.Money; paus; Juhtum "ntext": dbType = SqlDbType.NText; paus; Juhtum "Nvarchar": dbType = SqlDbType.NVarChar; paus; juhtum "smalldatetime": dbType = SqlDbType.SmallDateTime; paus; Juhtum "Smallint": dbType = SqlDbType.SmallInt; paus; Juhtum "tekst": dbType = SqlDbType.Text; paus; Juhtum "Bigint": dbType = SqlDbType.BigInt; paus; juhtum "binaarne": dbType = SqlDbType.Binaarne; paus; Juhtum "Char": dbType = SqlDbType.Char; paus; Juhtum "nchar": dbType = SqlDbType.NChar; paus; Juhtum "numbriline": dbType = SqlDbType.Decimal; paus; Juhtum "päris": dbType = SqlDbType.Real; paus; Juhtum "väikeraha": dbType = SqlDbType.SmallMoney; paus; Juhtum "sql_variant": dbType = SqlDbType.Variant; paus; Juhtumi "ajatempel": dbType = SqlDbType.Timestamp; paus; Juhtum "Tinyint": dbType = SqlDbType.TinyInt; paus; Juhtum "unikaalne identifikator": dbType = SqlDbType.UniqueIdentifier; paus; Juhtum "varbinaarne": dbType = SqlDbType.VarBinary; paus; Juhtum "XML": dbType = SqlDbType.Xml; paus;
} return dbType;
} Kopeeri sisu kirjutusaluseleKood:SQL Serveri andmetüübid, teisendatuna tüübitüüpideks C# keeles public static Type SqlTypeString2CsharpType(string sqlTypeString)
{ SqlDbType dbTpe = SqlTypeString2SqlType(sqlTypeString);
return SqlType2CsharpType(dbTpe);
}
Teisenda andmetüübid SQL Serveris C# tüüpide jadadeks. avalik staatiline string SqlTypeString2CsharpTypeString(string sqlTypeString)
{ Type type = SqlTypeString2CsharpType(sqlTypeString);
Tagastustüüp. Nimi;
}
|