将SQLServer数据类型转换为.Net中SqlDbType类型


  将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数据类型转换为.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




C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务

版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:将SQLServer数据类型转换为C#.Net类型
下一篇:截取指定像素长度的字符串
评论列表

发表评论

评论内容
昵称:
关联文章

SQLServer数据类型转换.NetSqlDbType类型
SQLServer数据类型转换C#.Net类型
SqlDbType与DbType类型互相转换
MsSql数据类型SqlDbType)与.NET类型(Type)对应关系
MsSql数据类型(SqlDbType)名称对应.NET类型(Type)
MsSQL数据类型(SqlDbType)名称对应DbType类型
SQLServer2005数据库转换SQLServer2000
C#.NET DateTime时间格式转换Unix时间戳格式(int类型)
C# object类型,c# object
C#数据转换类ConvertEx,封装.Net的Convert对象
TypeConverter.ConvertFromString 通用方法:字符串转换具体的类型
SQLServer LinkServer链接服务器:未服务器配置用于RPC
C# WebApi查询字符串RequestUri.Query解析转换Hashtable
C# GUID转换最长16位的短字符串序号
怎样DAL层提交数据默认系统数据库?
C#数据导出到Excel汇总
VS2010出现无法嵌入互操作类型
MySql数据类型(MySqlDbType)与.NET类型(Type)对应关系
MySql数据类型(MySqlDbType)名称对应.NET类型(Type)
C# 数组、集合、可枚举类型转换成逗号分隔的字符串(String.Join)

热门标签
.NET5 .NET6 .NET7 APP Auth-软件授权注册系统 Axios B/S B/S开发框架 Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 DAL数据访问层 Database datalock DbFramework Demo教学 Demo下载 DevExpress教程 DOM EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS NavBarControl Node.JS NPM OMS ORM PaaS POS Promise API Redis SAP SEO SQL SQLConnector TMS系统 Token令牌 VS2022 VSCode VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 版本区别 报表 踩坑日记 操作手册 代码生成器 迭代开发记录 基础资料窗体 架构设计 角色权限 开发sce 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 秘钥 密钥 权限设计 软件报价 软件测试报告 软件简介 软件开发框架 软件开发平台 软件开发文档 软件体系架构 软件下载 软著证书 三层架构 设计模式 生成代码 实用小技巧 收钱音箱 数据锁 数据同步 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序