Click to See Complete Forum and Search --> : Update DATABASE using DataAdapter's update method


raulbolanos
August 6th, 2009, 07:26 AM
Hi guys,

I want to update this datatable into my DB but the table in the DB that I use, it doesn't use Primary Key and I really don't need it. Therefore I get this Exception error (System.InvalidOperationException: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information).

If I go to the DB and I add a new column into the table and assign it like PK it works but I really want to avoid this and keep the table like that.

Any suggestion please?

Thank you in advance

JonnyPoet
August 6th, 2009, 08:55 AM
[quote=raulbolanos;1867249]... it doesn't use Primary Key and I really don't need it. Therefore I get this Exception error (System.InvalidOperationException: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information).
[/quoté]
Yes very easy:
Are there any columns which have only unique values then use that column and declare it as unique and to be the primary key.

If you cannot have single one row which is filled with unique values, maybe you will have two or more columns who together are resulting in a unique condition. For example Consider a tabel which has two columns: post_section_No and streetname. You may have streetnames and they are not unique itself, because there are some streets with the same name in different districts so you have different post-Section-numbers with the same streetname. On the other side your post destrict names are also not unique, because you have lots of streets in each district. But both columns together are one key because a defined post-section-No together with a streetname is unique. ( Consider you dont have the same name in the same district twice, which can happen here in Vienna :D ! )
Ok in this example we would simple declare streetname together with post_section_No to be the unique key and that all about.

If you dont have any possibility for a unique key define one. There is no way around, because how the program should differ between two lines if it has no exact data which one is to be updated. So how this should work then. You would need to compare all columns to find a specific line then and what happens if even this is not unique ?

I dont know anything about your database, but if you dont have a possibility for a Primary Key, maybe you need to change your design. Maybe simple add an autoincrement number and all is done.
There is no other way out then the described one.