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);
    代码虽然只是有一点不同,但是实现的方法却有很大的差别,做事要一丝不苟,留下此文时时提醒自己。
  • 相关阅读:
    jquery3.0移除了.load()方法
    drupal7 formAPI给元素加css样式
    drupal7,注册成功之后想跳转到指定页面,该怎么破?
    PHP的new self() 与new static()
    PHP网站(Drupal7)响应过慢之“Wating(TTFB)时间过长”
    Django的url别名功能的使用
    JavaScript学习之路
    CSS学习之路
    Html学习之路
    Django之Models
  • 原文地址:https://www.cnblogs.com/chengbo/p/99020.html
Copyright © 2011-2022 走看看