Deleting Child Table Rows and not from the master table using SqlDataAdapter.Update()

I have two tables tblPerson and tblPhone. 
tblPerson has:
PersonID
Name

tblPhone has:
PhoneID
PersonID
PhoneNumber

I am using SqlDataAdapter.Update to delete the rows from the tables. I am also using Typed DataSets and the relation between the two tables depends upon the PersonID. When I delete from the tblPerson the corresponding record of that person is also deleted from the tblPhone which is good. When I try to delete from the tblPhone I dont want the Person record to be deleted and it throws exception: 

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Any idea how this can be accomplish !


HighOnCoding
Wanna get high!
0
azamsharp
7/22/2005 4:07:42 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

0 Replies
704 Views

Similar Articles

[PageSpeed] 43

Reply:

Similar Artilces:

Showing table columns from multiple tables in Formview, but insert/update/delete rows of Master table
I have a page on which I have GridView and FomView control. On selection of a row in GridView the row gets displayed in the Item template of the FormVIew. The values are the result of inner join from multiple tables i.e. table Stock,Product and Workshop.  Please let me know how I could insert/update/delete data for the base table i.e. Stock table, but be able to see the column values from the associated tables on the Itemtemplate,Edittemplate and Inserttemplate of the FormView. Thanks,Anita Hi:   Take a look at this tutorial. It's for DetailsView and same ...

Deleting the master table withour deleting the child tables
Hi i have to delete the master table data without deleting the child table records,is there any solution for this,  parent table has relation with the child table. regards vinod.t.vSoftware EngineerUshustechTechnoparkTrivandrum India You need to temporarily disable constraints on the table. Disable constraints: ALTER TABLE MyTable NOCHECK CONSTRAINT ALL Enable constraints: ALTER TABLE MyTable CHECK CONSTRAINT ALL    If this post was useful to you, please mark it as answer. Thank you! Thanks johram i can try this solution, this is usefullSoftware Enginee...

Update a rows in one table for each row in other table
Hello all, i am a newbie in SQL and i want to ask for your help in order to do the following update statement. I have a table tblUsers which holds all the users, one of the fields in their GroupId. In the UserGroup table i have a field "UsersCount" and in that field i want to keep the number of the users in that group. Basically i want everytime i am saving a user to recalculate the users in all usergroups. I am trying to have something like:SELECT User_GroupId, count(User_GroupId) as UsersCount FROM tblUsersWHERE DeletedFlag = 0 GROUP BY User_GroupId and then:"FOR EACH" User_GroupIdUPDAT...

Update row in Table A from row in Table B
Hello, I have 2 tables.... table A and table B. Ok, In a stored procedure, I pass in an int value @ID I want to get the row from Table B WHERE ID =@ID....and then UPDATE the Row in Table A that has the same ID...with the values from table B. Table A ID | Col1 | Col2 ----------------------- 2 a a Table B ID | Col1 | Col2 ----------------------- 2 b b I would like to update A.Col1 with B.Col1 and A.Col2 with B.Col2 Can someone help me out with this syntax? Thanks a lot. update tableA ...

How to delete a row from a table using Object data source???
class is : test.cspublic static void DeleteServerlist(int serverID) {string con = SiteProvider.Instance.ServerDocumentationAppConnectionString; SqlConnection cn = new SqlConnection(con);SqlCommand cmd = new SqlCommand("deletefromtestserver", cn); cn.Open();cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.Add("@ServerID", SqlDbType.Int).Value = serverID; cmd.ExecuteNonQuery(); cn.Close(); }   Test.aspx   <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="Tes...

Deleting rows from one table based upon rows in another table
I need to delete rows from table1 based on rows in table2. table1 has 1.5 million rows from which I need to delete 20,000 existing in table2. The table structures are the same and I must exactly match 10 (of the 15) columns in the tables. I also need to limit the number of rows being worked on, in a single transaction, to 500 or so. Hi Mike, try the following: set rowcount 500 DELETE table1 from table1 t1,table2 t2 where t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3=t2.col3 and ........ t1.col10=t2.col10 HTH. Regards P:S You must re-execute the DML statement above 40 time...

Stored Procedure that fetch each row of a table and update rows in another table
I am working with the following two tables: Category(NewID,OldID) Link(CategoryID,BusinessID) All fields are of Integer Type. I need to write a stored procedure in sql 2000 which works as follows: Select all the NewID and OldID from the Category Table (SELECT NewID,OldID FROM Category) Then for each rows fetched from last query, execute a update query in the Link table. For Example, Let @NID be the NewID for each rows and @OID be the OldID for each rows. Then the query for each row should be.. UPDATE Link SET CategoryID=@CID WHERE CategoryID=@OID Please help me ...

Concurrency violation while updating table using SqlDataAdapter.Update method
I am getting a concurrency error while updating my table using the sqlDataAdapter.Update method. I have looked at the other forum discussions about this error and am unable to find an answer to my problem. Here is my code: //This is the code inside a button_click event. The IngredientsDP is a component class that consists of a table called Ingredients. IngredientsDP ingredients = new IngredientsDP(); dsIngredients.IngredientsRow ingRow = dsIngredients2.Ingredients.NewIngredientsRow(); ingRow.RecipeBoxId=boxId; ingRow.RecipeId=recId; ingRow.IngredientSeq=1; ingRow.In...

Adding table rows to a table in an update panel
I'm trying to add table rows to a table that has already been added to the update panel (ie, in design view). When I run my code, the text changes on the page, but I dont get additional rows, its as if its forgetting about the first row that was already added and simply over writing it... Anyone got any thoughts?  I had a label in there before where I'd reference the label and add text to the existing text, that worked fine, the text that was already there just stayed and the dialogue got longer etc, why is it different with the table rows? Any help would be appreciated..Rega...

Is having a trigger that inserts a row in Table 'A', when a row in same table is inserted by ADo.Net code?
I want to insert a row for a Global user  in Table 'A' whenever ADO.Net code inserts a Local user row into same table. I recommended using a trigger to implement this functionality, but the DBA was against it, saying that stored proecedures should be used, since triggers are unreliable and slow down the system by placing unecessary locks on the table. Is this true OR the DBA is saying something wrong? My thinking is that Microsoft will never include triggers if they are unreliable and the DBA is just wanting to offload the extra DBA task of triggers to the programmer so that a s...

table = table object
hi, how to copy the all rows of a table to temporary table using javascript i have tried like this but it's not working ex:document.getelementbyId('tmpTable')=document.getelementbyId('baseTable'); is there any way to do this..?? thanks... icanmakeiteasy put both tables in 2 divs and do div1.innerHTML = div2.innerHTML;MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets i have tried that tooo... not workingicanmakeiteasy you are doing right. just change thisvar tempTable ;tempTable=document.gete...

How to move a row in a data table object to the top of the table? The data table is in a data set. The data is bound to a drop down list box.
I am maintaining some 2003 C#/asp.net code for a web application. In the application a table in a data set is usedto populate a drop down list box.(The drop down list box will display a list of names) Before the data set table is bound to the list box control, blank characters are inserted at the topof the data set table. The purpose of this, is to display a blank line in the drop down list box, when the list box isinitially displayed. This code works fine. (See lines 1-14 below). Now I have been asked to modify the source code so that instead of a blank line being inserted at to top of th...

Updating one table doesn't update another table using foreign key relationship
I created two tables named table1 and table2 using visual database tool . For table1 , the table defn is id int primary key ,name nvarchar(max) (allow null) and age int (allow null) For table2 , the table defn is id int primary key , address nvarchar(max) (allow null). I selected id from table1 and dragged it over to id in table2 and foreign key relationship was created. If i insert values into table1 say (2,"xyz",25) the values gets inserted. But if i select table2 to display id , it didn't show inserted id "2". I want table2 to update automatically i...

superreview requested: [Bug 346940] differentiate anti-phishing table updates from full table reloads : [Attachment 231860] v3: duh, use rename table
Tony Chang (Google) <tony@ponderer.org> has asked Darin Fisher (Google) <darin@meer.net> for superreview: Bug 346940: differentiate anti-phishing table updates from full table reloads https://bugzilla.mozilla.org/show_bug.cgi?id=346940 Attachment 231860: v3: duh, use rename table https://bugzilla.mozilla.org/attachment.cgi?id=231860&action=edit ...

Web resources about - Deleting Child Table Rows and not from the master table using SqlDataAdapter.Update() - asp.net.object-datasource

moredotnet
M ore d otnet .NET Interview Questions, ASP.NET, C#, VB.NET, XML, SQL Check Out http://www.dotnetUncle.com √ .NET NOTES OOPS in .NET .NET ...

Auto-Generating Wrapper Classes for Stored Procedures, Part 1: Using the AutoSproc Tool
Steve J. Rodgers Software Consultant March 2004 Applies to: Microsoft® Visual Studio® .NET Microsoft® Visual Basic® .NET Microsoft® Visual ...

CodeSOD: tblIsThere
... [dbo].[tblIsThere] ([isthere] [bit] NOT NULL)" Dim theCMD As New SqlClient.SqlCommand(SQL, clsConnect.connect) Dim itDA As New SqlClient.SqlDataAdapter(_ ...

Abdul Rahuman's blog: JSON
In my previous article i have covered an example of using JQGrid using MVC and Jason( You can find my previous article here . Based on the response ...

Abdul Rahuman's blog
In my previous article i have covered an example of using JQGrid using MVC and Jason( You can find my previous article here . Based on the response ...

Master Detail JQGrid using MVC and JSON
In my previous article i have covered an example of using JQGrid using MVC and Jason( You can find my previous article here . Based on the response ...

Resources last updated: 11/22/2015 10:49:12 AM