惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
量子位
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
L
LangChain Blog
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客

博客园 - 车神

怎么在本地进行域名解析 解决sql server数据库还原的时候出现一直显示还原中 密码正则表达式大全 UNIQUE约束添加规则 Linux配置nginx开机自启 netcore跨平台之 Linux部署nginx代理webapi 为.net Core WebApi 创建Linux守护进程 Linux-CentOS 部署 dotnetCore API /前端 VUE mongodb:常用命令大全 C# 如何获取SQL Server 中指定数据表的所有字段名和字段类型 vue+nginx编译部署 vue.js安装过程(npm安装) JS将/Date(1446704778000)/转换成str javascript工具函数 如何提高ASP.NET页面载入速度的方法 SQL Server遍历表的几种方法 SQL2005语句实现行转列,列转行 sql中获取周、月、季度、年的第一天与最后一天 sql时间函数
SqlServer数据类型、C#SqlDbType对应关系及转换
车神 · 2019-01-08 · via 博客园 - 车神
 1 // SqlDbType转换为C#数据类型
 2 public static Type SqlType2CsharpType(SqlDbType sqlType)
 3 {
 4     switch (sqlType)
 5     {
 6         case SqlDbType.BigInt:
 7             return typeof(Int64);
 8         case SqlDbType.Binary:
 9             return typeof(Object);
10         case SqlDbType.Bit:
11             return typeof(Boolean);
12         case SqlDbType.Char:
13             return typeof(String);
14         case SqlDbType.DateTime:
15             return typeof(DateTime);
16         case SqlDbType.Decimal:
17             return typeof(Decimal);
18         case SqlDbType.Float:
19             return typeof(Double);
20         case SqlDbType.Image:
21             return typeof(Object);
22         case SqlDbType.Int:
23             return typeof(Int32);
24         case SqlDbType.Money:
25             return typeof(Decimal);
26         case SqlDbType.NChar:
27             return typeof(String);
28         case SqlDbType.NText:
29             return typeof(String);
30         case SqlDbType.NVarChar:
31             return typeof(String);
32         case SqlDbType.Real:
33             return typeof(Single);
34         case SqlDbType.SmallDateTime:
35             return typeof(DateTime);
36         case SqlDbType.SmallInt:
37             return typeof(Int16);
38         case SqlDbType.SmallMoney:
39             return typeof(Decimal);
40         case SqlDbType.Text:
41             return typeof(String);
42         case SqlDbType.Timestamp:
43             return typeof(Object);
44         case SqlDbType.TinyInt:
45             return typeof(Byte);
46         case SqlDbType.Udt://自定义的数据类型
47             return typeof(Object);
48         case SqlDbType.UniqueIdentifier:
49             return typeof(Object);
50         case SqlDbType.VarBinary:
51             return typeof(Object);
52         case SqlDbType.VarChar:
53             return typeof(String);
54         case SqlDbType.Variant:
55             return typeof(Object);
56         case SqlDbType.Xml:
57             return typeof(Object);
58         default:
59             return null;
60     }
61 }
 1 // sql server数据类型(如:varchar)转换为SqlDbType类型
 2 public static SqlDbType SqlTypeToSqlDbType(string sqlTypeString)
 3 {
 4     SqlDbType dbType = SqlDbType.Variant;//默认为Object
 5 
 6     switch (sqlTypeString.ToLower())
 7     {
 8         case "int":
 9             dbType = SqlDbType.Int;
10             break;
11         case "varchar":
12             dbType = SqlDbType.VarChar;
13             break;
14         case "bit":
15             dbType = SqlDbType.Bit;
16             break;
17         case "datetime":
18             dbType = SqlDbType.DateTime;
19             break;
20         case "decimal":
21             dbType = SqlDbType.Decimal;
22             break;
23         case "float":
24             dbType = SqlDbType.Float;
25             break;
26         case "image":
27             dbType = SqlDbType.Image;
28             break;
29         case "money":
30             dbType = SqlDbType.Money;
31             break;
32         case "ntext":
33             dbType = SqlDbType.NText;
34             break;
35         case "nvarchar":
36             dbType = SqlDbType.NVarChar;
37             break;
38         case "smalldatetime":
39             dbType = SqlDbType.SmallDateTime;
40             break;
41         case "smallint":
42             dbType = SqlDbType.SmallInt;
43             break;
44         case "text":
45             dbType = SqlDbType.Text;
46             break;
47         case "bigint":
48             dbType = SqlDbType.BigInt;
49             break;
50         case "binary":
51             dbType = SqlDbType.Binary;
52             break;
53         case "char":
54             dbType = SqlDbType.Char;
55             break;
56         case "nchar":
57             dbType = SqlDbType.NChar;
58             break;
59         case "numeric":
60             dbType = SqlDbType.Decimal;
61             break;
62         case "real":
63             dbType = SqlDbType.Real;
64             break;
65         case "smallmoney":
66             dbType = SqlDbType.SmallMoney;
67             break;
68         case "sql_variant":
69             dbType = SqlDbType.Variant;
70             break;
71         case "timestamp":
72             dbType = SqlDbType.Timestamp;
73             break;
74         case "tinyint":
75             dbType = SqlDbType.TinyInt;
76             break;
77         case "uniqueidentifier":
78             dbType = SqlDbType.UniqueIdentifier;
79             break;
80         case "varbinary":
81             dbType = SqlDbType.VarBinary;
82             break;
83         case "xml":
84             dbType = SqlDbType.Xml;
85             break;
86     }
87     return dbType;
88 }