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);
    代码虽然只是有一点不同,但是实现的方法却有很大的差别,做事要一丝不苟,留下此文时时提醒自己。
  • 相关阅读:
    最近学习下,nohup和&的区别
    java 关键字
    iOS之事件穿透
    排序算法——快速排序
    分布式-选举算法
    分布式选举算法
    SolrCloud 分布式集群部署步骤
    linux 启动两个tomcat
    solr安装-tomcat+solrCloud构建稳健solr集群
    JAVA 中BIO,NIO,AIO的理解
  • 原文地址:https://www.cnblogs.com/chengbo/p/99020.html
Copyright © 2011-2022 走看看