SQL SERVER与C#的数据类型对应表
序号
|
类别
|
SQLServer
|
C Sharp
|
备注
|
1
|
整数
|
bit
|
Boolean
|
True转换为1False转换为0
|
2
|
tinyint
|
Byte
|
C Sharp 数据类型都位于System命名空间
|
|
3
|
smallint
|
Int16
|
||
4
|
int
|
Int32
|
||
5
|
bigint
|
Int64
|
||
6
|
smallmoney
|
Decimal
|
||
7
|
money
|
Decimal
|
||
8
|
numeric
|
Decimal
|
||
9
|
decimal
|
Decimal
|
||
10
|
浮点数
|
float
|
Double
|
|
11
|
real
|
Single
|
||
12
|
日期和时间
|
smalldatetime
|
DateTime
|
|
13
|
datetime
|
DateTime
|
||
14
|
timestamp
|
DateTime
|
||
15
|
字符串
|
char
|
String
|
|
16
|
text
|
String
|
||
17
|
varchar
|
String
|
||
18
|
nchar
|
String
|
||
19
|
ntext
|
String
|
||
20
|
nvarchar
|
String
|
||
21
|
二进制数据
|
binary
|
Byte[]
|
|
22
|
varbinary
|
Byte[]
|
||
23
|
image
|
Byte[]
|
||
24
|
其他
|
uniqueidentifier
|
Guid
|
|
25
|
Variant
|
Object
|
SqlDbType => DbType
SqlDbType.BigInt DbType.Int64 SqlDbType.Binary DbType.Binary SqlDbType.Bit DbType.Boolean SqlDbType.Char DbType.AnsiStringFixedLength SqlDbType.DateTime DbType.DateTime SqlDbType.Decimal DbType.Decimal SqlDbType.Float DbType.Double SqlDbType.Image DbType.Binary SqlDbType.Int DbType.Int32 SqlDbType.Money DbType.Currency SqlDbType.NChar DbType.StringFixedLength SqlDbType.NText DbType.String SqlDbType.NVarChar DbType.String SqlDbType.Real DbType.Single SqlDbType.UniqueIdentifier DbType.Guid SqlDbType.SmallDateTime DbType.DateTime SqlDbType.SmallInt DbType.Int16 SqlDbType.SmallMoney DbType.Currency SqlDbType.Text DbType.AnsiString SqlDbType.Timestamp DbType.Binary SqlDbType.TinyInt DbType.Byte SqlDbType.VarBinary DbType.Binary SqlDbType.VarChar DbType.AnsiString SqlDbType.Variant DbType.Object SqlDbType.Xml DbType.Xml SqlDbType.Udt DbType.Object SqlDbType.Structured DbType.Object SqlDbType.Date DbType.Date SqlDbType.Time DbType.Time SqlDbType.DateTime2 DbType.DateTime2 SqlDbType.DateTimeOffset DbType.DateTimeOffset
/// <summary>
/// 数据库中与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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2015-07-10 cannot find the word template:WordToRqm.dot的解决方法
2015-07-10 ASP.NET操作Word的IIS权限配置
2015-07-10 VS2010中的调试技巧
2015-07-10 VS2010如何调试IIS上的网站