Using DataAdapter.Update to insert / update rows in dataset (not based on PK database)

I have a batch process that reads data from multiple tables into a dataset based on a shared key. Then I create a second dataset of the destination data query on the same key.

At this point, I have two datasets that are structurally identical (from a table / column perspective). Then I have a process that adds any row that exists in the source to the target dataset. In addition, the process will try to update some of the columns based on the shared key.

The problem occurs when the DataAdapter.UPDATE command is called with existing rows that need to be updated. Error: Fixing System.InvalidOperationException was unhandled Message = "The table referenced in the SELECT statement does not contain a unique key or ID column, or the SELECT statement does not include all key columns."

Since I have no way of controlling what PK is in the destination DB, is there a way to tell the adapter what is the key for this particular update? I have a "custom" set of primary keys for each DataTable in the dataset.

It is a non-user front-end batch process and its primary requirements are quite low. (explain the use of datasets, etc.)

Any thoughts?

+1


source to share


2 answers


db profile and see which requests get fired. copy the requests from Profiler and try to execute them manually. if they fail then the problem is with sql and the error is coming from the db and just pushed to your application.



this should at least tell u if the problem is caused by a missing real PK in the db.

+1


source


you need to set PK for each table in the dataset, just like you do. I don't think there is a way for the adapter to understand what a PC is in itself. if there is, and someone knows it, I'm all ears.



0


source







All Articles