C# 与 SQL Server 的数据类型对应关系
(一)C#与SQL Server 2005(或以下版本):
|
C# |
C#取值 |
SQL Server |
SQL Server取值 |
|
System.DateTime |
samlltime |
||
|
System.Object |
variant |
(二)C#与SQL Server 2008(或以上版本):
|
C# |
C#取值 |
SQL Server |
SQL Server取值 |
|
System.Boolean |
true/false |
bit |
1/0 |
|
System.SByte |
-128~127 |
||
|
System.Byte |
0~255 |
tinyint |
0~255 |
|
System.Int16 |
-32768~32767 |
smallint |
-32768~32767 |
|
System.UInt16 |
0~65535 |
||
|
System.Int32 |
-2147483648~2147483647 |
int |
-2147483648~2147483647 |
|
System.UInt32 |
0~4294967295 |
||
|
System.Int64 |
-9223372036854775808~ 9223372036854775807L |
bigint |
-9223372036854775808~9223372036854775807 |
|
System.UInt64 |
0~18446744073709551615UL |
||
|
System.Single |
real |
||
|
System.Double |
float |
||
|
System.Decimal |
smallmoney |
-214748.3648~214748.3647 |
|
|
money |
-922337203685477.5808~922337203685477.5807 |
||
|
decimal |
-999999999999999999.49~999999999999999999.49 |
||
|
numeric |
1~38位 |
||
|
System.Char |
|||
|
System.String |
char |
1~8000 |
|
|
varchar |
1~8000 |
||
|
nchar |
1~4000 |
||
|
nvarchar |
1~4000 |
||
|
text |
|||
|
ntext |
|||
|
time |
00:00:00.0000000~23:59:59.9999999 |
||
|
System.DateTime |
date |
0001-01-01~9999-12-31 |
|
|
smalldatetime |
|||
|
datetime |
1753-01-01 00:00:00:000~9999-12-31 23:59:59.997 |
||
|
datetime2 |
|||
|
datetimeoffset |
|||
|
System.Byte[] |
timestamp |
||
|
image |
|||
|
binary |
|||
|
varbinary |
|||
|
System.Guid |
uniqueidentifier |
||
|
System.Object |
sql_variant |
(三)根据数据库数据类型字符,获取C#中对应的数据类型字符
1 /// <summary>
2 /// 将数据库数据类型字符串,转为C#数据类型字符串。
3 /// </summary>
4 /// <param name="dbType">数据库数据类型字符串。</param>
5 /// <returns>C#数据类型字符串。</returns>
6 private static string DBTypeToCSharpType(string dbType)
7 {
8 string cSharpType = string.Empty;
9 switch (dbType.ToLower())
10 {
11 case "bit":
12 cSharpType = "bool";
13 break;
14 case "tinyint":
15 cSharpType = "byte";
16 break;
17 case "smallint":
18 cSharpType = "short";
19 break;
20 case "int":
21 cSharpType = "int";
22 break;
23 case "bigint":
24 cSharpType = "long";
25 break;
26 case "real":
27 cSharpType = "float";
28 break;
29 case "float":
30 cSharpType = "double";
31 break;
32 case "smallmoney":
33 case "money":
34 case "decimal":
35 case "numeric":
36 cSharpType = "decimal";
37 break;
38 case "char":
39 case "varchar":
40 case "nchar":
41 case "nvarchar":
42 case "text":
43 case "ntext":
44 cSharpType = "string";
45 break;
46 case "samlltime":
47 case "date":
48 case "smalldatetime":
49 case "datetime":
50 case "datetime2":
51 case "datetimeoffset":
52 cSharpType = "System.DateTime";
53 break;
54 case "timestamp":
55 case "image":
56 case "binary":
57 case "varbinary":
58 cSharpType = "byte[]";
59 break;
60 case "uniqueidentifier":
61 cSharpType = "System.Guid";
62 break;
63 case "variant":
64 case "sql_variant":
65 cSharpType = "object";
66 break;
67 default:
68 cSharpType = "string";
69 break;
70 }
71 return cSharpType;
72 }
C# 与 SQL Server 的数据类型对应关系的更多相关文章
- SQL Server常见数据类型介绍
数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 1.整数类型 int 存储范围是-2,147,483,648到2,147,483 ...
- Sql Server之数据类型详解
数据类型是一种属性,用于指定对象可保存的数据的类型,SQL Server中支持多种数据类型,包括字符类型.数值类型以及日期类型等.数据类型相当于一个容器,容器的大小决定了装的东西的多少,将数据分为 ...
- SQL Server 常见数据类型介绍
数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 整数类型 int 存储范围是-2,147,483,648到2,147,483,6 ...
- 说说SQL Server的数据类型
以SQL Server为例,SQL Server的数据类型总共有33种,归纳为一下类别: 精确数字 Unicode字符串 近似数字 二进制字符串 日期和时间 其他数据类型 字符串 1.数字数据类型 ...
- SQL SERVER的数据类型
1.SQL SERVER的数据类型 数据类弄是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或 ...
- sql server 字符数据类型
SQL Server 中字符类型包括varchar.char.text等.主要用于存储字符数据.varchar和char类型的主要区别在于数据填充.例如,一个列名为FirstName且数据类型为var ...
- 通过SQL Server自定义数据类型实现导入数据
写在前面 在看同事写的代码时看到了SQL Server中可以自定义数据类型,而且定义的是DataTable类型的数据类型. 后我想起了以前我们导入数据时要么是循环insert写入,要么是SqlBulk ...
- Sql Server 自定义数据类型
SQLServer 提供了 25 种基本数据类型: ·Binary [(n)] 二进制数据 既可以是固定长度的(Binary),也可以是变长度的.其中,n 的取值范围是从 1 到 8000.其存储窨 ...
- SQL Server datetime数据类型设计、优化误区
一.场景 在SQL Server 2005中,有一个表TestDatetime,其中Dates这个字段的数据类型是datetime,如果你看到表的记录如下图所示,你最先想到的是什么呢? (图1:数据列 ...
随机推荐
- Docker镜像加速设置
地址:https://www.daocloud.io/mirror#accelerator-doc 配置 Docker 加速器 Linux MacOS Windows curl -sSL https: ...
- HTML5 & auto download image
HTML5 & auto download image https://www.sitepoint.com/new-html5-attributes-hyperlinks-download-m ...
- SVG to Image in js
SVG to Image in js SVG to Image https://image.online-convert.com/convert-to-svg https://stackoverflo ...
- loadrunner分析结果二
5 worst transaction transaction name:事务名 failure ratio[%](exceeded time/transaction duration)失败率 (超标 ...
- 【Mysql】—— 索引的分类
注意:索引是在存储引擎中实现的,也就是说不同的存储引擎,会使用不同的索引.MyISAM和InnoDB存储引擎:只支持BTREE索引,也就是说默认使用BTREE,不能够更换.MEMORY/HEAP存储引 ...
- BZOJ2173 整数的lqp拆分(生成函数)
首先有序整数拆分有个显然的递推式是g(n)=Σg(i) (i=0~n-1),即枚举加入最后一个数之前和是多少.(虽然不用递推式也能显然地知道答案是2n-1). 类似地,lqp拆分有递推式f(n)=Σf ...
- POI 生成excel(大数据量) SXSSF
使用POI 的SXSSF (Streaming Usermodel API)生成较大的excel,同时开启压缩 import junit.framework.Assert; import org.ap ...
- 通过 powershell 配置 IIS
1. 设置iis pool: cls Import-Module WebAdministration Get-ChildItem IIS:\apppools | ForEach-Object{ ...
- android 混淆 与 反编译
1, 文件 project.properties 修改: target=android-14proguard.config=${sdk.dir}/tools/proguard/proguard-and ...
- hdu 1097 A hard puzzle 快速幂取模
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10. /*A ha ...