[求助]SqlCommandBuilder在如下代码中的作用??
下面这两段代码中,红色部份的代码是什么意思????起什么作用?1.下面这段代码中,红色部份的代码是什么意思????
SqlConnection thisConn = new SqlConnection(strSqlConnection);
thisConn.Open();
SqlDataAdapter this.Adapter = new SqlDataAdapter("SELECT CustomerID,CompanyName FROM Customers" thisConn);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
SqDataAdapter custAdapter = new SqlDataAdapter("SELECT * FROM Customers",thisConn);
SqDataAdapter orderAdapter = new SqlDataAdapter("SELECT * FROM Orders",thisConn);
custAdapter.Fill(thisDataSet,"Customers");
orderAdapter.Fill(thisDataSet,"Orders");
DataRelation custOrderRel = this.DataSet.Retations.Add("CustOrders",thisDataSet.Tables["Customers"].Columns["CustomerID"],
thisDataSet.Table["Orders"].Columns["CustomerID"]);
foreach(DataRow custRow in thisDataSet.Tables["Customers"].Rows)
{
Console.WriteLine("Customer ID:" + custRow["CustomerID"] + " Name:" + custRow["CompanyName"]);
foreach(DataRow orderRow in custRow.GetChildRows(CustOrderRel))
{
Console.WriteLine(" Order ID:" + orderRow["OrderID"]);
}
}
thisConn.Close();
2.下面这段代码中,红色部份的代码是什么意思????
SqlConnection thisConn = new SqlConnection(strSqlConnection);
thisConn.Open();
SqlDataAdapter this.Adapter = new SqlDataAdapter("SELECT CustomerID,CompanyName FROM Customers" thisConn);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet,"Customers");
Console.WriteLine("name before change:{0}",thisDataSet.Table["Customers"].Rows[9]["CompanyName"]);
thisDataSet.Tables["Customers"].Rows[9]["CompanyName"] = "Acme,Inc";
thisAdapter.Update(this.DataSet,"Customers");
Console.WriteLine("name after change:{0}",thisDataSet.Table["Customers"].Rows[9]["CompanyName"]);
thisConn.Close();