MalcomTucker
MalcomTucker

Reputation: 7477

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 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;

Upvotes: 0

Views: 462

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273571

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

Upvotes: 2

Related Questions