delete multiple rows from table doesnt contain primary key

K

Kayıhan

In my project,i added datagridview to my form , i transfered my table to
datagridview and added multiple rows and when i called dataadapther.update
,,result is ok. But when i tried it for the delete operations,i got the
error like "set primary key in your table" ,,i want delete multiple rows from
Datatable which doesnt contain primary key
 
P

Peter Bromberg [C# MVP]

If your table doesn't have a primary key, then you'll need to supply a WHERE
clause that is distinct enough to disambiguate which rows to delete.
Peter
 
K

Kayıhan

instead of supply where clause, i prefer choose row from table and delete it
with
"row.Delete(); dataAdapther.Update(table);" . idont understand why i am not
allowed; what is the harm about it? why primary key is needed for delete but
not for insert or update operations?
thanks
 
L

Lasse Vågsæther Karlsen

Kayıhan said:
instead of supply where clause, i prefer choose row from table and delete it
with
"row.Delete(); dataAdapther.Update(table);" . idont understand why i am not
allowed; what is the harm about it? why primary key is needed for delete but
not for insert or update operations?
thanks

What if you have multiple rows with the same data? I know you can simply
say "I know I don't", but .NET can't *know* that, and it requires
something to uniquely identify the rows to delete.

On a different note, every table should have a primary key or you'll
most likely have problems with it later on, like duplicate data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top