C#数据访问层的相关知识有哪些

技术C#数据访问层的相关知识有哪些这篇文章给大家分享的是有关C#数据访问层的相关知识有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。C#数据访问层1.查询数据库中的数据,返回一个datat

这篇文章给大家分享的是有关C#数据访问层的相关知识有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

C#数据访问层1.查询数据库中的数据,返回一个数据表

C#数据访问层2.执行一条结构化查询语言语句已重载

使用系统;使用系统.数据;使用努尼特.框架;使用代码文件管理器。项目;使用系统.数据。SqlClient使用系统.配置;命名空间操作符b {//////class 1的摘要说明///[NUnit .框架。TestFixture]公共类operatordb { privatestticstringstrcon=配置设置.AppSettings[' ConnectionString '];privateintModuleId=1;publicationstatisticstringconnectionstring { get { returnstrCon;}设置{ strCon=value} } #地区'初始化[努涅特.框架。TestFixtureSetUp]public void register _ Module(){ stringModuleName=' OperatorDB ';stringModuleAuthor=' MYM ';stringModuleDescribe='数据访问模块;stringCreateDatetime=' 2003-5-30 ';ModuleId=项目。插入模块(模块名、模块作者、模块描述、创建日期时间);}[Test]public void register _ Method _ SelectData(){ stringMethodName=' SelectData ';stringMethodAuthor=' MYM ';stringMethodCreateDateTime=' 2005-3-30 ';stringMethodParaMeters=' ParaMeters(StringSqlCommandText,System .数据。DataTableDt,boolrowslocker)';stringMethodReturn=' bool '字符串方法所有不间断空格

;= "" ;  string MethodDescribe = "查询数据库中的数据,返回一个datatable";  Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId);   }  [Test]  public void Register_Method_ExecuteSql()  {  string MethodName = "ExecuteSql";  string MethodAuthor = "MYM";  string MethodCreateDateTime = "2005-3-30";  string MethodParaMeters ="ParaMeters(string SqlCommandText)";  string MethodReturn = "int";  string MethodCall = "" ;  string MethodDescribe = "执行一条SQL语句";  Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId);   }  [Test]  public void Register_Method_SerialNumber()  {  string MethodName = "SerialNumber";  string MethodAuthor = "MYM";  string MethodCreateDateTime = "2005-3-30";  string MethodParaMeters ="ParaMeters(int index, System.Data.DataTable dt)";  string MethodReturn = "void";  string MethodCall = "" ;  string MethodDescribe = "给表的指定列添加序号";  Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId);   }   #endregion   public static bool SelectData(string SqlCommandText, System.Data.DataTable Dt, bool RowsClearr)   {   strCon = ConfigurationSettings.AppSettings["ConnectionString"];   bool ret = true;   if (SqlCommandText != "")   {   if (RowsClearr)   {   if (Dt.Rows.Count > 0)  {  Dt.Rows.Clear();   }   }   SqlConnection cn = new SqlConnection(strCon);   SqlDataAdapter da = new SqlDataAdapter(SqlCommandText, cn);   try   {   cn.Open();   da.Fill(Dt);   }   catch (System.Exception ex)   {   ExceptionHand exc = new ExceptionHand(ex);   exc.DisplayErrorMessager("OperatorDB","SelectData",SqlCommandText);   ret = false;   }   if (cn.State == ConnectionState.Open)   {   cn.Close();   }   da.Dispose();   }   else   {   ret = false;   }   return ret;   }   public static int ExecuteSql(string SqlCommandText)   {   int ID = 0;   strCon = ConfigurationSettings.AppSettings["ConnectionString"];   if (SqlCommandText != "")   {   SqlConnection cn = new SqlConnection(strCon);   SqlCommand cm = new SqlCommand(SqlCommandText, cn);   try   {   cn.Open();  ID = Convert.ToInt32(cm.ExecuteScalar());  }   catch (System.Exception ex)   {   cn.Close();  ExceptionHand exc = new ExceptionHand(ex);   exc.DisplayErrorMessager("OperatorDB","ExecuteSql",SqlCommandText);   ID = -1;   }    if (cn.State == ConnectionState.Open)   {   cn.Close();   }   cm.Dispose();   }   return ID;   }   public static int ExecuteSql(SqlCommand Cm)   {   int ID = 0;   strCon = ConfigurationSettings.AppSettings["ConnectionString"];   SqlConnection cn = new SqlConnection(strCon);   try   {   cn.Open();   Cm.Connection = cn;  ID = Convert.ToInt32(Cm.ExecuteScalar());   }   catch (System.Exception ex)   {   cn.Close();  ExceptionHand exc = new ExceptionHand(ex);   exc.DisplayErrorMessager("OperatorDB","ExecuteSql",Cm.CommandText);   ID = -1;   }    if (cn.State == ConnectionState.Open)   {   cn.Close();   }   Cm.Dispose();    return ID;   }   public static void SerialNumber(int index, System.Data.DataTable dt)   {   for (int i = 0; i <= dt.Rows.Count - 1; i++)   {   dt.Rows[i][index] = i + 1;   }   }   public static void SetSqlCommandValues(SqlCommand Com,DataTable Dt,int Index,int StartIndex)  {  int i;  for (i=StartIndex;i{  Com.Parameters.Add("@" + Dt.Columns[i].ColumnName,Dt.Rows[Index][i]);  }  }   }  }

感谢各位的阅读!关于“C#数据访问层的相关知识有哪些”这篇文章就分享到这里了,希望

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/128941.html

(0)

相关推荐

  • PostgreSQL如何实现自动更新时间戳

    技术PostgreSQL如何实现自动更新时间戳这篇文章主要介绍PostgreSQL如何实现自动更新时间戳,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!什么是PostgreSQL时间戳数据类型?在P

    攻略 2021年11月24日
  • 学习笔记 2021.12.9cont

    技术学习笔记 2021.12.9cont 学习笔记 2021.12.9cont2021.12.9
    聚合函数
    常见的聚合函数
    具体的count的使用场景的比较(默认具体字段没有非空的)。这里涉及到更多底层

    礼包 2021年12月10日
  • qt 场景视图画地图(qt图片绘制区域得到点坐标)

    技术Qt如何编写地图实现省市区域图这篇文章主要介绍了Qt如何编写地图实现省市区域图,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。一、前言省市区域图也可以叫

    攻略 2021年12月20日
  • 如何用TPYBoard开发板制作PM2.5检测仪

    技术如何用TPYBoard开发板制作PM2.5检测仪今天就跟大家聊聊有关如何用TPYBoard开发板制作PM2.5检测仪,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收

    攻略 2021年12月22日
  • HIVE如何统计每个地区最热门的TOP3产品?

    技术HIVE如何统计各个区域下最热门的TOP3的商品小编给大家分享一下HIVE如何统计各个区域下最热门的TOP3的商品,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!环境: hadoop-2

    攻略 2021年12月16日
  • Oracle 11g 遇到log file sync严重等待事件该怎么办

    技术Oracle 11g 遇到log file sync严重等待事件该怎么办这篇文章将为大家详细讲解有关Oracle 11g 遇到log file sync严重等待事件该怎么办,文章内容质量较高,因此小编分享给大家做个参

    攻略 2021年11月30日