By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

delete multiple rows from table doesnt contain primary key

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Kayıhan" <Ka****@discussions.microsoft.comwrote in message
news:A0**********************************@microsof t.com...
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
Jun 27 '08 #2

P: n/a
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

"Peter Bromberg [C# MVP]" wrote:
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

"Kayıhan" <Ka****@discussions.microsoft.comwrote in message
news:A0**********************************@microsof t.com...
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
Jun 27 '08 #3

P: n/a
Kayıhan wrote:
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

"Peter Bromberg [C# MVP]" wrote:
>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

"Kayıhan" <Ka****@discussions.microsoft.comwrote in message
news:A0**********************************@microso ft.com...
>>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
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.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.