小编Bun*_*top的帖子

使用Dataadapter更新时发生DBConcurrency异常

我正在尝试编辑DataTable填充NpgsqlDataAdapter.在调用Fill()方法之后,我只有一行DataTable.然后我只更改了一列的值,并尝试更新如下.

在此输入图像描述

然后我收到这个错误:

发生了DBConcurrencyException

我的代码是:

NpgsqlDataAdapter getAllData = new NpgsqlDataAdapter("SELECT sn,
code,product, unitprice, quantity, InvoiceNo, Date FROM stocktable WHERE Code='" + product + "'
 ORDER BY EDate ASC", DatabaseConnectionpg);
DataTable ds1 = new DataTable();
ds1.Clear();
getAllData.Fill(ds1);

if (ds1.Rows.Count > 0)
{
    ds1.Rows[0]["Quantity"] = qty;// calculated value
}
ds1 = ds1.GetChanges();

NpgsqlCommandBuilder cb = new NpgsqlCommandBuilder(getAllData);
//getAllData.RowUpdating += (sender2, e2) => { e2.Command.Parameters.Clear(); };
//cb.SetAllValues = false;
getAllData.DeleteCommand = cb.GetDeleteCommand();
getAllData.InsertCommand = cb.GetInsertCommand();
getAllData.UpdateCommand …
Run Code Online (Sandbox Code Playgroud)

c# postgresql npgsql

6
推荐指数
1
解决办法
1207
查看次数

标签 统计

c# ×1

npgsql ×1

postgresql ×1