Why does a typed dataset cause an insert rather than an update (causing primary key violation)?
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.
精彩评论