欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ADO.NET通用數(shù)據(jù)庫(kù)訪問(wèn)類

 更新時(shí)間:2016年03月17日 14:50:12   作者:TuringChang  
這篇文章主要為大家介紹了ADO.NET通用數(shù)據(jù)庫(kù)訪問(wèn)類,利用ADO.NET的體系架構(gòu)打造通用的數(shù)據(jù)庫(kù)訪問(wèn)通用類,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ADO.NET通用數(shù)據(jù)庫(kù)訪問(wèn)類,供大家參考學(xué)習(xí),具體內(nèi)容如下

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



using System.Data;

using System.Data.SqlClient;



namespace Test

{

  public class DBHelper

  {

    public static string ConString = "Data Source=.;Initial Catalog=bankdb;User id=sa;Password=123;";



    //執(zhí)行增刪改的方法

    public static int RunNoQuery(string cmdText, CommandType cmdType, params SqlParameter[] pars)

    {

      SqlConnection con = new SqlConnection(ConString);

      con.Open();

      SqlCommand cmd = new SqlCommand(cmdText, con);

      cmd.CommandType = cmdType;

      if (pars != null && pars.Length > 0)

      {

        foreach (SqlParameter p in pars)

        {

          cmd.Parameters.Add(p);

        }

      }

      int rows = cmd.ExecuteNonQuery();

      con.Close();

      return rows;

    }



    //執(zhí)行查詢(DataSet)的方法

    public static DataSet RunSelect(string cmdText, CommandType cmdType, params SqlParameter[] pars)

    {

      SqlConnection con = new SqlConnection(ConString);

     

      SqlDataAdapter da = new SqlDataAdapter(cmdText, con);

      da.SelectCommand.CommandType = cmdType;

      if (pars != null && pars.Length > 0)

      {

        foreach (SqlParameter p in pars)

        {

          da.SelectCommand.Parameters.Add(p);

        }

      }

      DataSet ds = new DataSet();

      da.Fill(ds);



      return ds;

    }



    //執(zhí)行查詢得到一個(gè)值

    public static object RunOneValue(string cmdText, CommandType cmdType, params SqlParameter[] pars)

    {

      SqlConnection con = new SqlConnection(ConString);

      con.Open();

      SqlCommand cmd = new SqlCommand(cmdText, con);

      cmd.CommandType = cmdType;

      if (pars != null && pars.Length > 0)

      {

        foreach (SqlParameter p in pars)

        {

          cmd.Parameters.Add(p);

        }

      }

      object obj = cmd.ExecuteScalar();

      con.Close();

      return obj;

    }

  }

}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論