Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
There are two tables:

VB
Table1 : UserID Name Job
Table2 : BookID Book Car UserID


I load these two tables in one wpf datagrid:

C#
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
Updated 19-Jan-13 20:14pm
v3

1 solution

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
 
Share this answer
 
Comments
M.H. Shojaei 20-Jan-13 2:47am    
New column(IsDeleted) in which Table? 1 or 2.
[no name] 20-Jan-13 2:53am    
table 2. Means the table from where you want to delete the records.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900