开发者

Why does a typed dataset cause an insert rather than an update (causing primary key violation)?

开发者 https://www.devze.com 2023-03-06 00:29 出处:网络
I\'m trying to use a dataset to update some rows in a database, simple. I\'m creating a typed dataset instance, disabling constraints, adding a few rows to one table and populating a few of the colu

I'm trying to use a dataset to update some rows in a database, simple.

I'm creating a typed dataset instance, disabling constraints, adding a few rows to one table and populating a few of the columns in the rows, including the primary开发者_JS百科 key, with existing and correct primary key values. Yet, when I call update on the data adapter it's throwing a primary key violation.

I'm not providing values for every column, only those I want to update. Why does the adapter not recognise an update is required?

MyDataset dataSet = new MyDataset();
dataSet.EnforceConstraints = false;


Simply because you Add() the records... That marks them as new and they will trigger an Insert statement on update.

0

精彩评论

暂无评论...
验证码 换一张
取 消