|
SqlConnection nwindConn = new SqlConnection (@ "server = TEST\HR; database = test; uid = sa; pwd = 123456");
SqlDataAdapter dataAdpater = new SqlDataAdapter ("SELECT CustomerID, Address, CompanyName FROM Customers", nwindConn);
dataAdpater.UpdateCommand = new SqlCommand ("UPDATE Customers SET CompanyName = @CompanyName" + "WHERE CustomerID = @CustomerID", nwindConn);
dataAdpater.UpdateCommand.Parameters.Add ("@ CompanyName", SqlDbType.NVarChar, 15, "CompanyName");
SqlParameter parameter = dataAdpater.UpdateCommand.Parameters.Add ("@ CustomerID", SqlDbType.Int);
parameter.SourceColumn = "CustomerID";
parameter.SourceVersion = DataRowVersion.Original;
DataSet dataSet = new DataSet ();
dataAdpater.Fill (dataSet, "Customers");
DataRow row = dataSet.Tables ["Customers"]. Rows [0];
row ["CompanyName"] = "New 1111CompanyName";
dataSet.AcceptChanges ();
DataRow row1 = dataSet.Tables ["Customers"]. Rows [1];
row1 ["CompanyName"] = "New 12211CompanyName";
dataAdpater.Update (dataSet, "Customers");
////Display Data
Label1.Text = dataSet.Tables ["Customers"]. Rows [0] ["CompanyName"]. ToString ();
Label2.Text = dataSet.Tables ["Customers"]. Rows [0] ["CustomerID"]. ToString ();
Label3.Text = dataSet.Tables ["Customers"]. Rows [1] ["CompanyName"]. ToString ();
Label4.Text = dataSet.Tables ["Customers"]. Rows [1] ["CustomerID"]. ToString ();
The error displayed after execution is: "Concurrency violation: UpdateCommand affected 0 of the expected 1 record."
Because I want to record multiple changes at the same time, I wonder if it is possible. |
|