C#底层库--数据库类型与程序类型转换类

系列文章

C#底层库–记录日志帮助类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/124187709

C#底层库–数据库访问帮助类(MySQL版)
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126886379

C#底层库–获取文件版本和MD5值
本文链接:https://blog.csdn.net/youcheng_ge/article/details/112513871

C#底层库–操作文件帮助类FileHelper(获取目录的所有文件)
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126887161

C#底层库–操作Excel帮助类(读取、导出表格)
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126887445

C#底层库–软件版本管理XML
本文链接:https://blog.csdn.net/youcheng_ge/article/details/110195766

C#底层库–随机数生成类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/126888812

C#底层库–正则表达式帮助类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/109745286

C#底层库–CSV和DataTable相互转换
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128804367

C#底层库–Image图片操作类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128805298

C#底层库–JSON序列化、反序列化扩展类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128805705

C#底层库–cookie操作辅助类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128816347

C#底层库–Session操作辅助类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128817096

C#底层库–数据实体类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128816638

C#底层库–Image图片操作类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/128805298

文章目录

  • 系列文章
  • 前言
  • 一、底层库介绍
  • 二、底层库源码
  • 三、调用方法
  • 三、项目案列


前言

本专栏为【底层库】,将介绍研发过程中 通用的函数。我们将这些固化的源码,进行重写、规范封装、单元测试、集成测试,从而形成通用化模块库,本专栏称为“底层库”。

作为研发人员的你,并不需要花大量时间,完全掌握“底层库”的含义,你只需要几行调用代码,就可以解决一些项目上碰到的难题。大家有任何问题,可以评论区反馈,私信我。

底层库已实现功能:数据库操作、加解密算法、日志记录、HTTP通信、Socket通信、API前后端交互、邮件发送、文件操作、配置参数存储、Excel导入导出、CSV和DataTable转换、压缩解压、自动编号、Session操作等,

一、底层库介绍

数据库类型与程序类型转换类。数据库数据类型与编程开发语言数据类型是不一样的,本类是在基础上做转换。

二、底层库源码

创建类DataTypeConverter,复制以下代码。

using System;
using System.Collections.Generic;
using System.Text;

namespace GYC_Util.Common
{
    public class DataTypeConverter
    {
        
        
        public static string SqlTypeToCS(string type)
        {
            
            string reval = String.Empty;
            switch (type.ToLower())
            {
                case "int":
                    reval = typeof(System.Int32).ToString();// "int32";
                    break;
                case "text":
                    reval = "string";
                    break;
                case "bigint":
                    reval = "int64";
                    break;
                case "binary":
                    reval = "system.byte[]";
                    break;
                case "bit":
                    reval = "boolean";
                    break;
                case "char":
                    reval = "string";
                    break;
                case "datetime":
                    reval = "system.datetime";
                    break;
                case "decimal":
                    reval = "system.decimal";
                    break;
                case "float":
                    reval = "system.double";
                    break;
                case "image":
                    reval = "system.byte[]";
                    break;
                case "money":
                    reval = "system.decimal";
                    break;
                case "nchar":
                    reval = "string";
                    break;
                case "ntext":
                    reval = "string";
                    break;
                case "numeric":
                    reval = "system.decimal";
                    break;
                case "nvarchar":
                    reval = "string";
                    break;
                case "real":
                    reval = "system.single";
                    break;
                case "smalldatetime":
                    reval = "system.datetime";
                    break;
                case "smallint":
                    reval = "int16";
                    break;
                case "smallmoney":
                    reval = "system.decimal";
                    break;
                case "timestamp":
                    reval = "system.datetime";
                    break;
                case "tinyint":
                    reval = "system.byte";
                    break;
                case "uniqueidentifier":
                    reval = "system.guid";
                    break;
                case "varbinary":
                    reval = "system.byte[]";
                    break;
                case "varchar":
                    reval = "string";
                    break;
                case "variant":
                    reval = "object";
                    break;
                default:
                    reval = "string";
                    break;
            }
            return reval;
        }

//        bit Boolean True转换为1False转换为0 
//2 tinyint Byte C Sharp 数据类型都位于System命名空间 
//3 smallint Int16 
//4 int Int32 
//5 bigint Int64 
//6 smallmoney Decimal 
//7 money Decimal 
//8 numeric Decimal 
//9 decimal Decimal 
//10 浮点数 float Double 
//11 real Single 
//12 日期和时间 smalldatetime DateTime 
//13 datetime DateTime 
//14 timestamp DateTime 
//15 字符串 char String 
//16 text String 
//17 varchar String 
//18 nchar String 
//19 ntext String 
//20 nvarchar String 
//21 二进制数据
 
//  binary Byte[] 
//22 varbinary Byte[] 
//23 image Byte[] 
//24 其他 uniqueidentifier Guid 
//25 Variant Object 


    }
}


三、调用方法

我放在了窗体页面,新增一个按钮,点击按钮时触发。

public static int GetIntValue(this int? v,int def)
{
    if (v.HasValue) return v.Value;
    return def;
}

三、项目案列

你可能感兴趣的:(C#,底层库(工具,通用类),c#,数据库,开发语言)