Questo articolo è un articolo speculare di traduzione automatica, clicca qui per saltare all'articolo originale.

Vista: 10363|Risposta: 0

[Fonte] I tipi SQL Server corrispondono ai tipi C#

[Copiato link]
Pubblicato su 19/01/2016 11:04:06 | | | |


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;
}






Precedente:Il significato del valore di ritorno return_value in SQL Server
Prossimo:.net converte DataTable in una collezione
Disconoscimento:
Tutto il software, i materiali di programmazione o gli articoli pubblicati dalla Code Farmer Network sono destinati esclusivamente all'apprendimento e alla ricerca; I contenuti sopra elencati non devono essere utilizzati per scopi commerciali o illegali, altrimenti gli utenti dovranno sostenere tutte le conseguenze. Le informazioni su questo sito provengono da Internet, e le controversie sul copyright non hanno nulla a che fare con questo sito. Devi eliminare completamente i contenuti sopra elencati dal tuo computer entro 24 ore dal download. Se ti piace il programma, ti preghiamo di supportare software autentico, acquistare la registrazione e ottenere servizi autentici migliori. In caso di violazione, vi preghiamo di contattarci via email.

Mail To:help@itsvse.com