|
楼主 |
发表于 2020-4-15 13:30:01
|
显示全部楼层
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");
////显示数据
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();
执行后显示错误为:"违反并发性: UpdateCommand 影响了预期 1 条记录中的 0 条。"
因为我想同时多条改动的记录,不知可不可以. |
|