首页 > C# > C# 等效于 SQL Server 数据类型

C# 等效于 SQL Server 数据类型

上一篇 下一篇

对于以下 SQL Server 数据类型,C# 中对应的数据类型是什么?

精确数字

bigint
numeric
bit
smallint
decimal
smallmoney
int
tinyint
money

近似数字

float
real

日期和时间

date
datetimeoffset
datetime2
smalldatetime
datetime
time

字符串

char
varchar
text

统一码字符串

nchar
nvarchar
ntext

二进制字符串

binary
varbinary
image

其他数据类型

cursor
timestamp
hierarchyid
uniqueidentifier
sql_variant
xml
table

(来源:MSDN)

分割线

网友回答:

这适用于 SQL Server 2005。该表有适用于 SQL Server 2008、SQL Server 2008 R2、SQL Server 2012 和 SQL Server 2014 的更新版本。

SQL Server 数据类型及其等效项 .NET Framework

下表列出了 Microsoft SQL Server 数据类型、它们在 System.Data.SqlTypes 命名空间中 SQL Server 的公共语言运行时 (CLR) 中的等效项,以及它们在 Microsoft .NET Framework 中的本机 CLR 等效项。

SQL Server 数据类型 CLR 数据类型 (SQL Server) CLR 数据类型(.NET Framework)
瓦二进制 SqlBytes, SqlBinary 字节[]
二元的 SqlBytes, SqlBinary 字节[]
变量二进制(1), 二进制(1) SqlBytes, SqlBinary 字节,字节[]
图像 没有 没有
瓦尔查尔 没有 没有
没有 没有
恩瓦尔查尔(1), 恩查尔(1) SqlChars, SqlString 字符, 字符串, 字符[]
恩瓦尔查尔 SqlChars, SqlString 字符串,字符[]
查尔 SqlChars, SqlString 字符串,字符[]
发短信 没有 没有
ntext 没有 没有
唯一标识符 SqlGuid 吉德
行版本 没有 字节[]
SqlBoolean 布尔
天银 SqlByte 字节
斯莫林特 SqlInt16 国际16
国际 SqlInt32 国际32
比金特 SqlInt64 国际64
小钱 SqlMoney 十进制
SqlMoney 十进制
数值的 SqlDecimal 十进制
十进制 SqlDecimal 十进制
真正 SqlSingle
SqlDouble
小日期时间 SqlDateTime 日期时间
日期时间 SqlDateTime 日期时间
sql_variant 没有 对象
用户定义类型(UDT) 没有 用户定义类型
桌子 没有 没有
光标 没有 没有
时间戳 没有 没有
.xml SqlXml 没有

分割线

网友回答:

SQL Server 和 .Net 数据类型映射

分割线

网友回答:

如果有人正在寻找从 C# 和 SQL Server 格式转换的方法,这里有一个简单的实现:

private readonly string[] SqlServerTypes = { "bigint", "binary", "bit",  "char", "date",     "datetime", "datetime2", "datetimeoffset", "decimal", "filestream", "float",  "geography",                              "geometry",                              "hierarchyid",                              "image",  "int", "money",   "nchar",  "ntext",  "numeric", "nvarchar", "real",   "rowversion", "smalldatetime", "smallint", "smallmoney", "sql_variant", "text",   "time",     "timestamp", "tinyint", "uniqueidentifier", "varbinary", "varchar", "xml" };
private readonly string[] CSharpTypes    = { "long",   "byte[]", "bool", "char", "DateTime", "DateTime", "DateTime",  "DateTimeOffset", "decimal", "byte[]",     "double", "Microsoft.SqlServer.Types.SqlGeography", "Microsoft.SqlServer.Types.SqlGeometry", "Microsoft.SqlServer.Types.SqlHierarchyId", "byte[]", "int", "decimal", "string", "string", "decimal", "string",   "Single", "byte[]",     "DateTime",      "short",    "decimal",    "object",      "string", "TimeSpan", "byte[]",    "byte",    "Guid",             "byte[]",    "string",  "string" };

public string ConvertSqlServerFormatToCSharp(string typeName)
{
    var index = Array.IndexOf(SqlServerTypes, typeName);

    return index > -1
        ? CSharpTypes[index]
        : "object";
}

public string ConvertCSharpFormatToSqlServer(string typeName)
{
    var index = Array.IndexOf(CSharpTypes, typeName);

    return index > -1
        ? SqlServerTypes[index]
        : null;
}

编辑:修正错别字

模板简介:该模板名称为【C# 等效于 SQL Server 数据类型】,大小是暂无信息,文档格式为.编程语言,推荐使用Sublime/Dreamweaver/HBuilder打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【C#】栏目查找您需要的精美模板。

相关搜索
  • 下载密码 lanrenmb
  • 下载次数 187次
  • 使用软件 Sublime/Dreamweaver/HBuilder
  • 文件格式 编程语言
  • 文件大小 暂无信息
  • 上传时间 04-07
  • 作者 网友投稿
  • 肖像权 人物画像及字体仅供参考
栏目分类 更多 >
热门推荐 更多 >
单页式简历模板 自适应 微信素材 微信文章 微信公众平台 html5 微信模板 微信图片 企业网站 响应式
您可能会喜欢的其他模板