【SqlServer数据类型、C#数据类型、SqlDbType】对应关系及转换
// sql server数据类型(如:varchar)
// 转换为SqlDbType类型
public static SqlDbType SqlTypeString2SqlType(string sqlTypeString)
{
SqlDbType dbType = SqlDbType.Variant;//默认为Object
switch (sqlTypeString)
{
case "int":
dbType = SqlDbType.Int;
break;
case "varchar":
dbType = SqlDbType.VarChar;
break;
case "bit":
dbType = SqlDbType.Bit;
break;
case "datetime":
dbType = SqlDbType.DateTime;
break;
case "decimal":
dbType = SqlDbType.Decimal;
break;
case "float":
dbType = SqlDbType.Float;
break;
case "image":
dbType = SqlDbType.Image;
break;
case "money":
dbType = SqlDbType.Money;
break;
case "ntext":
dbType = SqlDbType.NText;
break;
case "nvarchar":
dbType = SqlDbType.NVarChar;
break;
case "smalldatetime":
dbType = SqlDbType.SmallDateTime;
break;
case "smallint":
dbType = SqlDbType.SmallInt;
break;
case "text":
dbType = SqlDbType.Text;
break;
case "bigint":
dbType = SqlDbType.BigInt;
break;
case "binary":
dbType = SqlDbType.Binary;
break;
case "char":
dbType = SqlDbType.Char;
break;
case "nchar":
dbType = SqlDbType.NChar;
break;
case "numeric":
dbType = SqlDbType.Decimal;
break;
case "real":
dbType = SqlDbType.Real;
break;
case "smallmoney":
dbType = SqlDbType.SmallMoney;
break;
case "sql_variant":
dbType = SqlDbType.Variant;
break;
case "timestamp":
dbType = SqlDbType.Timestamp;
break;
case "tinyint":
dbType = SqlDbType.TinyInt;
break;
case "uniqueidentifier":
dbType = SqlDbType.UniqueIdentifier;
break;
case "varbinary":
dbType = SqlDbType.VarBinary;
break;
case "xml":
dbType = SqlDbType.Xml;
break;
}
return dbType;
}
// SqlDbType转换为C#数据类型
public static Type SqlType2CsharpType(SqlDbType sqlType)
{
switch (sqlType)
{
case SqlDbType.BigInt:
return typeof(Int64);
case SqlDbType.Binary:
return typeof(Object);
case SqlDbType.Bit:
return typeof(Boolean);
case SqlDbType.Char:
return typeof(String);
case SqlDbType.DateTime:
return typeof(DateTime);
case SqlDbType.Decimal:
return typeof(Decimal);
case SqlDbType.Float:
return typeof(Double);
case SqlDbType.Image:
return typeof(Object);
case SqlDbType.Int:
return typeof(Int32);
case SqlDbType.Money:
return typeof(Decimal);
case SqlDbType.NChar:
return typeof(String);
case SqlDbType.NText:
return typeof(String);
case SqlDbType.NVarChar:
return typeof(String);
case SqlDbType.Real:
return typeof(Single);
case SqlDbType.SmallDateTime:
return typeof(DateTime);
case SqlDbType.SmallInt:
return typeof(Int16);
case SqlDbType.SmallMoney:
return typeof(Decimal);
case SqlDbType.Text:
return typeof(String);
case SqlDbType.Timestamp:
return typeof(Object);
case SqlDbType.TinyInt:
return typeof(Byte);
case SqlDbType.Udt://自定义的数据类型
return typeof(Object);
case SqlDbType.UniqueIdentifier:
return typeof(Object);
case SqlDbType.VarBinary:
return typeof(Object);
case SqlDbType.VarChar:
return typeof(String);
case SqlDbType.Variant:
return typeof(Object);
case SqlDbType.Xml:
return typeof(Object);
default:
return null;
}
}
代码:
// sql server中的数据类型,转换为C#中的类型类型
public static Type SqlTypeString2CsharpType(string sqlTypeString)
{
SqlDbType dbTpe = SqlTypeString2SqlType(sqlTypeString);
return SqlType2CsharpType(dbTpe);
}
// 将sql server中的数据类型,转化为C#中的类型的字符串
public static string SqlTypeString2CsharpTypeString(string sqlTypeString)
{
Type type = SqlTypeString2CsharpType(sqlTypeString);
return type.Name;
}
【SqlServer数据类型、C#数据类型、SqlDbType】对应关系及转换的更多相关文章
- SqlServer数据类型、C#SqlDbType对应关系及转换
{ { } } { SqlDbType dbType = SqlDbType.Variant; { dbType = SqlDbType.Int; dbType = SqlDbType.VarChar ...
- SqlServer中的数据类型UniqueIdentifier
SqlServer中的数据类型UniqueIdentifier究竟是什么东东? 该类型一般用来做为主键使用,可用SQL语法的newid()来生成一个唯一的值.我想请问的是,这个值是一个长整型的数据值呢 ...
- 大数据学习--day02(标识符、变量、数据类型、类型转换、进制转换、原码反码补码)
标识符.变量.数据类型.类型转换.进制转换.原码反码补码 标识符: java50个关键字不能做标识符,以数字开头不能做标识符(这个老是忘记写一个类名的时候) 变量: 变量分为成员变量和局部变量,注意作 ...
- MySql Oracle SqlServer 数据库的数据类型列表
Oracle数据类型 一.概述 在ORACLE8中定义了:标量(SCALAR).复合(COMPOSITE).引用(REFERENCE)和LOB四种数据类型,下面详细介绍它们的特性. 二.标量(SCA ...
- python numPy模块 与numpy里的数据类型、数据类型对象dtype
学习链接:http://www.runoob.com/numpy/numpy-tutorial.html 官方链接:https://numpy.org/devdocs/user/quickstart. ...
- iOS有哪些数据类型/基本数据类型?
简述 本文主要探究使用OC作为iOS开发语言时,我们能使用哪些数据类型. 一切类型始于C. C语言的类型 基本数据类型: 基本数据类型(fundamental data types)也叫原始数据类型( ...
- Python数据类型-1 数据类型介绍
数据类型 在python这门语言中,数据类型分为两种. 内置的和自定义的. 内置的包括数字.字符串.布尔.列表.元组.字典.Bytes.集合这些常用的以及一些不太常用的数据类型.而自定义的,一般以类的 ...
- SQLServer和java数据类型的对应关系
转载自:https://www.cnblogs.com/cunkouzh/p/5504052.html SQL Server 类型 JDBC 类型 (java.sql.Types) Java 语言类型 ...
- Java基础(34):Java中基本数据类型的包装类(主要为了不同数据类型之间更方便的进行转换)(Wrapper类)
相信各位小伙伴们对基本数据类型都非常熟悉,例如 int.float.double.boolean.char 等.基本数据类型是不具备对象的特性的,比如基本类型不能调用方法.功能简单...,为了让基本数 ...
随机推荐
- Hive Map 端OOM 异常
怪异现象:数据量不大,且不是Reduce端OOM,是Map端OOM Map Task运行的时候数据流中包含了非法字符例如:EOF.NOP等东西,导致BufferedReader读取和StreamDec ...
- jQuery实时获取checkbox状态问题
在最近的项目开发中,使用jQuery操作checkbox时,发现一个问题. Html代码如下: <body> <div> <inputtype="checkbo ...
- font awesome使用笔记
背景 今天将BS项目部署到IIS服务器上时.首次打开一个使用font awesome图标集的页面是加载非常慢. 于是果断按下F12查看具体页面的请求时常.除去其他异步数据的加载消耗时间以外.我居然看到 ...
- Android常用工具类封装---SharedPreferencesUtil
SharedPreferences常用于保存一些简单的数据,如记录用户操作的配置等,使用简单. public class SharedPreferencesUtil { // ...
- 使用css3和伪元素制作的一个立体导航条
使用css3和伪元素制作的一个立体导航条供大家参考,代码如下: <!doctype html> <html lang="en"> <head> ...
- IM,游戏服务端 tcp 框架整理
Mina: Mina(Multipurpose Infrastructure for Network Applications) 是 Apache 组织一个较新的项目,它为开发高性能和高可用性的网络应 ...
- poj 3252 Round Numbers 数位dp
题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...
- grunt api 文档
Grunt docs Grunt和 Grunt 插件是通过 npm 安装并管理的,npm是 Node.js 的包管理器. 安装 grunt-cli npm install grunt-cli -g 注 ...
- cocos2dx 字体
有些时候需要在界面上显示些文字,自然涉及到字体的问题 显示文字使用CCLabelTTF即可,创建方法是 CCLabelTTF(const char* text, const char* font, i ...
- 美国vps哪个比较好,vps国内访问速度最快!
沃网中国是一家成立于2008年的国内idc商,提供基于hyper-v架构的VPS产品,数据中心包括国内电信.美国洛杉矶等,他们采用的是国内访问最快的加州机房ping值,160-180左右相当给力的速度 ...