zoukankan      html  css  js  c++  java
  • 关于建立多个SqlDataAdapter类实例的两种方法

    SqlDataAdapter有三种构造函数
    public SqlDataAdapter(SqlCommand);
    public SqlDataAdapter(string, SqlConnection);
    public SqlDataAdapter(stringstring);
    为了简便,建立多个SqlDataAdapter类实例时,通常我是这样的
    string strConn, strSqlEmployees, strSqlCustomers;
    strConn 
    = "server=.;uid=sa;pwd=chengbo;database=northwind;";
    strSqlEmployees 
    = "SELECT FirstName, LastName FROM Employees";
    strSqlCustomers 
    = "SELECT CustomerID, CompanyName FROM Customers";
    SqlDataAdapter daEmployees 
    = new SqlDataAdapter(strSqlEmployees, strConn);
    SqlDataAdapter daCustomers 
    = new SqlDataAdapter(strSqlCustomers, strConn);
    相比下面的代码,这样虽然少了一行,但是却建立了两个Connection
    string strConn, strSqlEmployees, strSqlCustomers;
    strConn 
    = "server=.;uid=sa;pwd=chengbo;database=northwind;";
    strSqlEmployees 
    = "SELECT FirstName, LastName FROM Employees";
    strSqlCustomers 
    = "SELECT CustomerID, CompanyName FROM Customers";
    SqlConnection Conn 
    = new SqlConnection(strConn);
    SqlDataAdapter daEmployees 
    = new SqlDataAdapter(strSqlEmployees, Conn);
    SqlDataAdapter daCustomers 
    = new SqlDataAdapter(strSqlCustomers, Conn);
    代码虽然只是有一点不同,但是实现的方法却有很大的差别,做事要一丝不苟,留下此文时时提醒自己。
  • 相关阅读:
    some ideas
    zz 牛人啊
    zz 史上最全--各银行借记卡的年费、小额管理费、转账费等!
    哪裡可以買郵票
    : 求靠谱灭蟑螂的方法
    zz 【见闻八卦】《金融时报》年度商业书单:互联网题材占一半
    IOS开发基础知识--碎片6
    IOS开发基础知识--碎片5
    IOS开发基础知识--碎片4
    IOS中关于KVC与KVO知识点
  • 原文地址:https://www.cnblogs.com/chengbo/p/99020.html
Copyright © 2011-2022 走看看