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);
    代码虽然只是有一点不同,但是实现的方法却有很大的差别,做事要一丝不苟,留下此文时时提醒自己。
  • 相关阅读:
    thinkphp5整合 gatewaywork实现聊天
    php输出日志
    php的ob函数实现页面静态化
    30个php操作redis常用方法代码例子
    redis三种启动方式
    Redis实战
    支付宝即时到账接口开发
    PHP生成excel表格文件并下载
    微信平台提供三种公众号
    【Performance】chrome调试面板
  • 原文地址:https://www.cnblogs.com/chengbo/p/99020.html
Copyright © 2011-2022 走看看