Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
There are two tables:

Table1 : UserID Name Job
Table2 : BookID Book Car UserID

I load these two tables in one wpf datagrid:

da.SelectCommand = new SqlCommand("select Table1.UserID, Table1.Name, Table1.Job, Table2.Book, Table2.Car from Table1 inner join Table2 on Table1.UserID = Table2.UserID");

How can delete a row from Table2 based on BookID?
thanks
Posted 19-Jan-13 18:54pm
Edited 19-Jan-13 21:14pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

HI,

Basically you can't be able to delete the record from the table having a foreign key in it. If you want to delete the record there are 2 ways of doing that.

1. Make your "cascade delete property" on in sql tables. But this will delete the records from the parent table too. This is not atall recomended.

2. Make a column named as IsDeleted of boolean type and set the value to 1 which record you want to delete. This is followed in most of the industries.

Thanks
  Permalink  
Comments
Mohammad Hossein Shojaei at 20-Jan-13 2:47am
   
New column(IsDeleted) in which Table? 1 or 2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 223
1 Sascha Lefévre 175
2 Abhinav S 170
3 Richard Deeming 155
4 CHill60 150
0 Sergey Alexandrovich Kryukov 7,156
1 OriginalGriff 6,410
2 Maciej Los 2,877
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100