Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2008

Tip: Looking for answers? Try searching our database.

delete multiple rows from table doesnt contain primary key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kayıhan - 14 May 2008 16:10 GMT
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
Peter Bromberg [C# MVP] - 14 May 2008 21:09 GMT
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

> In my project,i added datagridview to my form , i transfered my table to
> datagridview and  added multiple rows and when i called
[quoted text clipped - 3 lines]
> from
> Datatable which doesnt contain primary key
Kayıhan - 15 May 2008 08:13 GMT
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

> 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.
[quoted text clipped - 7 lines]
> > from
> > Datatable which doesnt contain primary key
Lasse Vågsæther Karlsen - 15 May 2008 09:02 GMT
> instead of supply where clause, i prefer choose row from table and delete it
> with
[quoted text clipped - 14 lines]
>>> 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.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.