Tipo SQL Server tipo C# bitbool tinyintbyte smallintshort intint bigintlong realfloat floatdouble moneydecimal dataoraora Scarstring varcharstring ncharstring nvarcharstring stringa di testo ntextstring imagebyte[] binarybyte[] uniqueidentifierGuid/ SqlDbType转换为C#数据类型 Public static Type SqlType2CsharpType(SqlDbType sqlType)
{ interruttore (sqlType)
{ Case SqlDbType.BigInt: tipo di ritorno (Int64); Case SqlDbType.Binary: return typeof(Object); caso SqlDbType.Bit: tipo di ritorno (booleano); case SqlDbType.Char: return typeof(String); caso SqlDbType.DateTime: return typeof(DateTime); Case SqlDbType.Decimal: return typeof(Decimal); caso SqlDbType.Float: ritorno tipo di (Doppio); caso SqlDbType.Image: return typeof(Object); Caso SqlDbType.Int: return typeof(Int32); Case SqlDbType.Money: return typeof(Decimal); caso SqlDbType.NChar: return typeof(String); caso SqlDbType.NText: return typeof(String); case SqlDbType.NVarChar: return typeof(String); Case SqlDbType.Real: tipo di ritorno (Singolo); caso SqlDbType.SmallDateTime: return typeof(DateTime); case SqlDbType.SmallInt: return typeof(Int16); Case SqlDbType.SmallMoney: return typeof(Decimal); caso SqlDbType.Text: return typeof(String); Case SqlDbType.Timestamp: return typeof(Object); caso SqlDbType.TinyInt: return typeof(Byte); case SqlDbType.Udt:// tipo di dato personalizzato return typeof(Object); caso SqlDbType.UniqueIdentifier: return typeof(Object); caso SqlDbType.VarBinary: return typeof(Object); caso SqlDbType.VarChar: return typeof(String); Case SqlDbType.Variant: return typeof(Object); case SqlDbType.Xml: return typeof(Object); Predefinito: return null;
}
}Copia il contenuto nella cartellinaCodice:Tipi di dati SQL Server (ad esempio, varchar) Converti in tipo SqlDbType pubblico statico SqlDbType SqlTypeString2SqlType(stringa sqlTypeString)
{ SqlDbType dbType = SqlDbType.Variant; Predefinito è Oggetto
interruttore (sqlTypeString)
{ Caso "int": dbType = SqlDbType.Int; pausa; Caso "Varchar": dbType = SqlDbType.VarChar; pausa; Caso "bit": dbType = SqlDbType.Bit; pausa; Caso "data": dbType = SqlDbType.DateTime; pausa; Minuscola "decimale": dbType = SqlDbType.Decimal; pausa; Caso "galleggiante": dbType = SqlDbType.Float; pausa; Caso "Immagine": dbType = SqlDbType.Image; pausa; Caso "denaro": dbType = SqlDbType.Money; pausa; Caso "Ntext": dbType = SqlDbType.NText; pausa; Caso "Nvarchar": dbType = SqlDbType.NVarChar; pausa; Caso "Smalldatetime": dbType = SqlDbType.SmallDateTime; pausa; Caso "smallint": dbType = SqlDbType.SmallInt; pausa; Caso "testo": dbType = SqlDbType.Text; pausa; Caso "bigint": dbType = SqlDbType.BigInt; pausa; Caso "binario": dbType = SqlDbType.Binary; pausa; Caso "Char": dbType = SqlDbType.Char; pausa; Caso "NCAR": dbType = SqlDbType.NChar; pausa; Caso "numerico": dbType = SqlDbType.Decimal; pausa; Caso "reale": dbType = SqlDbType.Real; pausa; Caso "smallmoney": dbType = SqlDbType.SmallMoney; pausa; Caso "sql_variant": dbType = SqlDbType.Variant; pausa; "Timestamp" del caso: dbType = SqlDbType.Timestamp; pausa; Caso "Tinyint": dbType = SqlDbType.TinyInt; pausa; Caso "Identificatore Unico": dbType = SqlDbType.Identificatore Unico; pausa; Caso "Varbinary": dbType = SqlDbType.VarBinary; pausa; Caso "XML": dbType = SqlDbType.Xml; pausa;
} return dbType;
} Copia il contenuto nella cartellinaCodice:Tipi di dati SQL Server, convertiti in tipi di tipo in C# Public static Type SqlTypeString2CsharpType (stringa sqlTypeString)
{ SqlDbType dbTpe = SqlTypeString2SqlType(sqlTypeString);
return SqlType2CsharpType(dbTpe);
}
Converti i tipi di dati in SQL Server in stringhe di tipi in C# stringa statica pubblica SqlTypeString2CsharpTypeString(string sqlTypeString)
{ Type type = SqlTypeString2CsharpType(sqlTypeString);
Tipo di restituzione. Nome;
}
|