Click here to Skip to main content
13,505,095 members
Rate this:
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?
Posted 19-Jan-13 17:54pm
Updated 19-Jan-13 20:14pm

1 solution

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

Solution 1


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.

Mohammad Hossein Shojaei 20-Jan-13 2:47am
New column(IsDeleted) in which Table? 1 or 2.
sisir patro 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2018
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