SqlDataAdapter有三种构造函数
为了简便,建立多个SqlDataAdapter类实例时,通常我是这样的
相比下面的代码,这样虽然少了一行,但是却建立了两个Connection
代码虽然只是有一点不同,但是实现的方法却有很大的差别,做事要一丝不苟,留下此文时时提醒自己。
public SqlDataAdapter(SqlCommand);
public SqlDataAdapter(string, SqlConnection);
public SqlDataAdapter(string, string);
public SqlDataAdapter(string, SqlConnection);
public SqlDataAdapter(string, string);
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);
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);
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);
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);