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:数据列 ...
随机推荐
- ThreadPoolExecutor参数
1.ThreadPoolExecutor个参数的意义(类上的注释内容) * @param corePoolSize the number of threads to keep in the* pool ...
- ACM数论之旅12---康托展开((*゚▽゚*)装甲展开,主推进器启动,倒计时3,2,1......)
在我们做题中,搜索也好,动态规划也好,我们往往有时候需要用一个数字表示一种状态 比如有8个灯泡排成一排,如果你用0和1表示灯泡的发光情况 那么一排灯泡就可以转换为一个二进制数字了 比如 0110011 ...
- Idea for Mac 过期 IntelliJ IDEA 2017 完美注册方法(附idea for Mac破解方法)
Idea 不能使用了: 开始破解: (1)首先下载 jar包: https://download.csdn.net/download/engerla/10573069 放到位置: /Applicati ...
- Ajax 響應
獲取服務器的響應內容,可以使用responseText或者responseXML屬性 responseText:獲取字符串形式的相應內容,除了XML的響應內容以外可用 responseXML:獲取XM ...
- codeforces166E
Tetrahedron CodeForces - 166E You are given a tetrahedron. Let's mark its vertices with letters A, B ...
- BZOJ3835[Poi2014]Supercomputer——斜率优化
题目描述 Byteasar has designed a supercomputer of novel architecture. It may comprise of many (identical ...
- Code POJ - 1780(栈模拟dfs)
题意: 就是数位哈密顿回路 解析: 是就算了...尼玛还不能直接用dfs,得手动开栈模拟dfs emm...看了老大半天才看的一知半解 #include <iostream> #inclu ...
- Debug时含有的子元素,在代码里获取不到的问题
比如,Debug时如下图展示: 我想要获取的是:ansList.get(i).getComponent().getConnectorId() debug时明明有这个元素,但是当我写出来的时候却发现:a ...
- Rsync 服务器端配置
Centos 6.3 已经自带Rsync服务 安装xinetd # yum -y install xinetd 编辑/etc/xinetd.d/rsync文件,把disable = yes修改为dis ...
- Nginx, HTTPS的配置
server {listen 443; ####HTTPS指定端口server_name www.web.com; #####域名或者IP root /data/wwwroot/l ...