将SQLServer数据类型转换为.Net中SqlDbType类型
将SQLServer数据类型转换为.Net中SqlDbType类型
SQLServer数据类型转换为.Net中SqlDbType类型(版本1)
/// <summary>
/// 将SQLServer数据类型名称(如:varchar)转换为.Net中SqlDbType类型(如:SqlDbType.VarChar)
/// </summary>
/// <param name="sqlTypeString">SQLServer数据类型名称</param>
/// <returns></returns>
public static SqlDbType SqlTypeName2SqlType(string sqlTypeString)
{
string[] SqlTypeNames = new string[] { "int", "varchar","bit" ,"datetime","decimal","float","image","money",
"ntext","nvarchar","smalldatetime","smallint","text","bigint","binary","char","nchar","numeric",
"real","smallmoney", "sql_variant","timestamp","tinyint","uniqueidentifier","varbinary","xml"};
SqlDbType[] SqlTypes = new SqlDbType[] {SqlDbType.Int,SqlDbType.VarChar,SqlDbType.Bit ,SqlDbType.DateTime,SqlDbType.Decimal,SqlDbType.Float,SqlDbType.Image,SqlDbType.Money,
SqlDbType.NText,SqlDbType.NVarChar,SqlDbType.SmallDateTime,SqlDbType.SmallInt,SqlDbType.Text,SqlDbType.BigInt,SqlDbType.Binary,SqlDbType.Char,SqlDbType.NChar,SqlDbType.Decimal,
SqlDbType.Real,SqlDbType.SmallMoney, SqlDbType.Variant,SqlDbType.Timestamp,SqlDbType.TinyInt,SqlDbType.UniqueIdentifier,SqlDbType.VarBinary,SqlDbType.Xml};
int i = Array.IndexOf(SqlTypeNames, sqlTypeString.ToLower());
return SqlTypes[i];
}
// 来源:www.CSFramework.com, C/S结构框架学习网
/// 将SQLServer数据类型名称(如:varchar)转换为.Net中SqlDbType类型(如:SqlDbType.VarChar)
/// </summary>
/// <param name="sqlTypeString">SQLServer数据类型名称</param>
/// <returns></returns>
public static SqlDbType SqlTypeName2SqlType(string sqlTypeString)
{
string[] SqlTypeNames = new string[] { "int", "varchar","bit" ,"datetime","decimal","float","image","money",
"ntext","nvarchar","smalldatetime","smallint","text","bigint","binary","char","nchar","numeric",
"real","smallmoney", "sql_variant","timestamp","tinyint","uniqueidentifier","varbinary","xml"};
SqlDbType[] SqlTypes = new SqlDbType[] {SqlDbType.Int,SqlDbType.VarChar,SqlDbType.Bit ,SqlDbType.DateTime,SqlDbType.Decimal,SqlDbType.Float,SqlDbType.Image,SqlDbType.Money,
SqlDbType.NText,SqlDbType.NVarChar,SqlDbType.SmallDateTime,SqlDbType.SmallInt,SqlDbType.Text,SqlDbType.BigInt,SqlDbType.Binary,SqlDbType.Char,SqlDbType.NChar,SqlDbType.Decimal,
SqlDbType.Real,SqlDbType.SmallMoney, SqlDbType.Variant,SqlDbType.Timestamp,SqlDbType.TinyInt,SqlDbType.UniqueIdentifier,SqlDbType.VarBinary,SqlDbType.Xml};
int i = Array.IndexOf(SqlTypeNames, sqlTypeString.ToLower());
return SqlTypes[i];
}
// 来源:www.CSFramework.com, C/S结构框架学习网
SQLServer数据类型转换为.Net中SqlDbType类型(版本2)
C# Code:
/// <summary>
/// MsSql数据类型简称对应.NET类型 - MsSql数据类型(SqlDbType)名称对应.NET类型(Type)
/// </summary>
public static IDictionary<string, Type> SqlDbTypeName2NetTypeMapping
{
get
{
IDictionary<String, Type> map = new Dictionary<String, Type>();
map.Add("BigInt", typeof(System.Int64));
map.Add("Binary", typeof(System.Byte[]));
map.Add("Bit", typeof(System.Boolean));
map.Add("Char", typeof(System.Char));
map.Add("Cursor", typeof(System.Object));//前端不用
map.Add("Date", typeof(System.DateTime));
map.Add("DateTime", typeof(System.DateTime));
map.Add("DateTime2", typeof(System.DateTime));
map.Add("DateTimeOffset", typeof(System.DateTimeOffset));
map.Add("Decimal", typeof(System.Decimal));
map.Add("Float", typeof(System.Double));
map.Add("Image", typeof(System.Byte[]));
map.Add("Int", typeof(System.Int32));
map.Add("Money", typeof(System.Decimal));
map.Add("NChar", typeof(System.String));
map.Add("NText", typeof(System.String));
map.Add("NVarChar", typeof(System.String));
map.Add("Real", typeof(System.Double));//float类型,double
map.Add("SmallDateTime", typeof(System.DateTime));
map.Add("SmallInt", typeof(System.Int16));
map.Add("SmallMoney", typeof(System.Decimal));
map.Add("sql_variant", typeof(System.Object));//sql_variant
map.Add("Structured", typeof(System.Object));//前端不用
map.Add("Text", typeof(System.String));
map.Add("Time", typeof(System.DateTime));
map.Add("Timestamp", typeof(System.DateTime));//byte[], 可以定义为datetime
map.Add("TinyInt", typeof(System.Int16));
map.Add("Udt", typeof(System.Object));//前端不用,UDT是用户自定义数据类型
map.Add("UniqueIdentifier", typeof(System.Guid));
map.Add("VarBinary", typeof(System.Byte[]));
map.Add("VarChar", typeof(System.String));
map.Add("Variant", typeof(System.Object));//sql_variant
map.Add("Xml", typeof(System.String));
return map;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// MsSql数据类型简称对应.NET类型 - MsSql数据类型(SqlDbType)名称对应.NET类型(Type)
/// </summary>
public static IDictionary<string, Type> SqlDbTypeName2NetTypeMapping
{
get
{
IDictionary<String, Type> map = new Dictionary<String, Type>();
map.Add("BigInt", typeof(System.Int64));
map.Add("Binary", typeof(System.Byte[]));
map.Add("Bit", typeof(System.Boolean));
map.Add("Char", typeof(System.Char));
map.Add("Cursor", typeof(System.Object));//前端不用
map.Add("Date", typeof(System.DateTime));
map.Add("DateTime", typeof(System.DateTime));
map.Add("DateTime2", typeof(System.DateTime));
map.Add("DateTimeOffset", typeof(System.DateTimeOffset));
map.Add("Decimal", typeof(System.Decimal));
map.Add("Float", typeof(System.Double));
map.Add("Image", typeof(System.Byte[]));
map.Add("Int", typeof(System.Int32));
map.Add("Money", typeof(System.Decimal));
map.Add("NChar", typeof(System.String));
map.Add("NText", typeof(System.String));
map.Add("NVarChar", typeof(System.String));
map.Add("Real", typeof(System.Double));//float类型,double
map.Add("SmallDateTime", typeof(System.DateTime));
map.Add("SmallInt", typeof(System.Int16));
map.Add("SmallMoney", typeof(System.Decimal));
map.Add("sql_variant", typeof(System.Object));//sql_variant
map.Add("Structured", typeof(System.Object));//前端不用
map.Add("Text", typeof(System.String));
map.Add("Time", typeof(System.DateTime));
map.Add("Timestamp", typeof(System.DateTime));//byte[], 可以定义为datetime
map.Add("TinyInt", typeof(System.Int16));
map.Add("Udt", typeof(System.Object));//前端不用,UDT是用户自定义数据类型
map.Add("UniqueIdentifier", typeof(System.Guid));
map.Add("VarBinary", typeof(System.Byte[]));
map.Add("VarChar", typeof(System.String));
map.Add("Variant", typeof(System.Object));//sql_variant
map.Add("Xml", typeof(System.String));
return map;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761

参考文档:
将SQLServer数据类型转换为C#.Net类型
SqlServer数据类型、DbType类型、.NET类型与达梦数据类型关系表|C/S开发框架
MySql数据类型(MySqlDbType)名称对应.NET类型(Type)
MsSql数据类型(SqlDbType)名称对应.NET类型(Type)
MySql数据类型(MySqlDbType)与.NET类型(Type)对应关系
MsSql数据类型(SqlDbType)与.NET类型(Type)对应关系
VS2022+.NET6:MySql时间戳(timestamp)类型对应EF Core类型注意事项
C#.NET 处理SQL特殊数据类型Geography/Geometry/Hierarchyid/XML
VS2022 .NET7手动更改组件类型(TextEdit改为ComboBoxEdit)|C/S开发框架
EFCore+.NET8:使用Oracle数据库提交大图片文件需要指定BLOB类型|C/S开发框架
SQL Server 数据类型对应.NET类型的EF模型定义|C/S开发框架
VS运行ASP.NET网站应用程序:“/”应用程序中的服务器错误。分析器错误,未能加载类型"XXX.Global"。
vs编译ASP.NET提示失败1个,error CS0246: 未能找到类型或命名空间名“CSFrameworkV5”(是否缺少 using 指令或程序集引用?
C#.NET 查询MYSQL报错:值类型与列类型不匹配不能在列中存储 。所需类型是MySqlDateTime
C#.NET给DataTable日期类型的列赋值报错:所需类型是 MySqlDateTime,值类型与列类型不匹配
MySQL数据类型(MySqlDbType)数据类型名称对应DbType类型
将SQLServer数据类型转换为C#.Net类型
SqlServer数据类型、DbType类型、.NET类型与达梦数据类型关系表|C/S开发框架
MySql数据类型(MySqlDbType)名称对应.NET类型(Type)
MsSql数据类型(SqlDbType)名称对应.NET类型(Type)
MySql数据类型(MySqlDbType)与.NET类型(Type)对应关系
MsSql数据类型(SqlDbType)与.NET类型(Type)对应关系
VS2022+.NET6:MySql时间戳(timestamp)类型对应EF Core类型注意事项
C#.NET 处理SQL特殊数据类型Geography/Geometry/Hierarchyid/XML
VS2022 .NET7手动更改组件类型(TextEdit改为ComboBoxEdit)|C/S开发框架
EFCore+.NET8:使用Oracle数据库提交大图片文件需要指定BLOB类型|C/S开发框架
SQL Server 数据类型对应.NET类型的EF模型定义|C/S开发框架
VS运行ASP.NET网站应用程序:“/”应用程序中的服务器错误。分析器错误,未能加载类型"XXX.Global"。
vs编译ASP.NET提示失败1个,error CS0246: 未能找到类型或命名空间名“CSFrameworkV5”(是否缺少 using 指令或程序集引用?
C#.NET 查询MYSQL报错:值类型与列类型不匹配不能在列中存储 。所需类型是MySqlDateTime
C#.NET给DataTable日期类型的列赋值报错:所需类型是 MySqlDateTime,值类型与列类型不匹配
MySQL数据类型(MySqlDbType)数据类型名称对应DbType类型
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
在线客服
