.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Update related tables

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Hi All, Forgive me if this is the wrong place to post this question. I looked for a forum on SQL statements but couldn't find one. I have a FormView with data from two tables in the SqlDataSource.  The second table is linked to the first by a FK/PK. There is an example from the Northwind SQL database, e.g. if the Products table is the main table but I want to display the Category Description in the FormView and edit it, how do I write the Update and Insert statements.? I have tried using the query builder in VS 2008  but it doesn't seem to work. Any help greatly appreciated. Regards,Penn

View Complete Post

More Related Resource Links

SqlDataAdapter.Update related tables



I would like to get 2 related tables from SQL Server to DataSet, insert new rows and save them back to SQL Db.

Let's say i have 2 related tables as shown below...

Table1 Table2
test1ID (Primary Key) test2ID (Primary Key)
data test1ID


In Sql i have Diagram with relationship and Update Rule is set to Cascade

I am trying to get them to dataset, insert "master" and "child" row and save them back to db.

I tried different approaches (none of them workes) and this is one of them:

Dim ds As New DataSet()
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("NastanitveConnectionString").ConnectionString)
        Dim sql As String = "SELECT * from Table1;Select * from Table2;"
        Dim d

How to update Sql Server related tables from Dataset(SchemaFill)

Hi!I would like to update new records that get inserted in DataSet to Sql Server Database.Below is a working example of how to do this if you use "DataAdapter.Fill(ds)". But i don't want to fill data, becouse i don't need data, i only need shema (I will use this dataset to insert new data to Sql), so i would like to use "DataAdapter.FillSchema(ds)"Please help me out at least with this one... i'm stuck... can't continue untill i crack this nut.<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True"> <Columns> <asp:CommandField ShowSelectButton="True" /> </Columns>

Gridview update problem with related tables


Hi all,

I have a problem in getting my gridview to update. The datasource gets its data from 2 related tables using the following select statement:

SELECT StudentSubject.StudentID, Students.[1stName], Students.Surname, Students.Grade, StudentSubject.Subject, StudentSubject.GradeOverall, StudentSubject.ReportYear, StudentSubject.ReportSession, StudentSubject.Criteria1Grade, StudentSubject.Criteria2Grade, StudentSubject.Criteria3Grade, StudentSubject.Criteria4Grade, StudentSubject.Criteria5Grade, StudentSubject.Criteria6Grade, StudentSubject.Criteria7Grade, StudentSubject.Criteria8Grade, StudentSubject.Criteria9Grade, StudentSubject.Criteria10Grade, StudentSubject.Comment
FROM (Students INNER JOIN StudentSubject ON Students.StudentID = StudentSubject.StudentID)
WHERE (StudentSubject.Subject = ?) AND (StudentSubject.ReportYear = ?) AND (Students.Grade = ?) AND (StudentSubject.ReportSession = ?)

The ? stem from combo box controls which I use to filter the results

So far so good!

However, when I try to update the data in just one of the tables, nothing happens, no error, just no update. The update statement I'm using is:

UPDATE StudentSubject SET GradeOverall = ?, Criteria1Grade = ?, Criteria8Grade = ?, Criteria7Grade = ?, Criteria6Grade = ?, Criteria5Grade = ?, Criteria4Grade = ?, Criteria3Grade = ?, Criteria2Grade = ?, Criteria

How to display related tables in one crystal report and how to link this report with combobox?


Hi! I want to display a crystal report in my vb.net application. Suppose I have tables named student details, student marks, student address, etc... Now if I want to display all these details (fields of all tables) in one crystal report (with page breaks if necessary) then how will I achieve it. I will be providing a combo box in my application that contains list of student names. How can I link this combo box with the cystal report to dynamically display report for different student on selected index change of combo box? Help me friends. An example would be appreciable.

Event Hanlder to update other SQL tables



I'm writing a small app to allow viewing and editing of a single SQL table (the _Assets table).

I have a form-view that allows the data to be viewed (ItemTemplate) and edited (EditItemTemplate).

Everything works well. All the SQL editing is done in the Mark-Up using a simple SqlDataSource, asp:Parameters and data-binding, (ie. there is no VB code behind).

However, I need to write an event-handler which updates other tables when the EditItemTemplate INSERT button is used.

This event handler needs to update OTHER SQL tables.

The idea is to create a HISTORY of changes (Updates) made to my _Assets table.

It would look something like this:

IF the value of the _Assets.Comments field is changed by the formview, then:

Open SQL connection to _CommentsHistory table

Update _CommentsHistory

SET CountrySerial = asp:Parameter Name "CountrySerial" from SqlDataSource ID="FindAsset"

SET OldComment = [the original Comment] asp:Parameter Name "Comments" from SqlDataSource ID="FindAsset"

SET NewComment = [the New Comment inserted in the formview] TextBox ID="CommentsTextBox" from FormView ID="FormView1"

SET ChangeDate = { fn (now)}

Set ChangedBy =

asp.net insert into 3 related tables using three tier architecture and typed datasets

I am using ASP.NET (C# and sql server express 2005) for my web application project. I have three related tables.I want to do an insert using typed datasets,tableadapters and three tier architecture.I wish to know how to do simultaneous inserts in 3 tables.So i wish to insert a row in first table and get its primary key.Same with the second table.I will use the primary keys of those first two tables to do the insert in the third table.How can i accomplish this using formview control and what methods should i use??Please give me suggestions.thanks in advance for reading this. I really appreciate it.

help with query - update from 2 tables

hi i have 2 tables     table1: num,X,Y     table2: num,X,Y i need to update X and Y in table1 where table1.num = table2.num how to do it ? i need it in Oracle query (i think that in sql server it will work too) thank's in advance 

Delete records if it is not getting inserted and also in the related tables

Hi All, If the insert into table person is successful, but the insert into table subject fails, delete the person record and all records associated with the person that were also inserted. If the insert into table person is successful, and the insert into subject is successful, but the insert into the booking table fails, delete the subject record, the person record ,and all records associated with the person that were also inserted. The reason for the failure into the 3 tables (person, subject, booking) should be logged to tblErrors . Also, a message should be written to tblErrors which logs the fact that this situation has occurred.     -- I have few stored procs which does inserts and updates How would i capture the record which is not getting inserted and log in to log table and delete the previous records which got inserted  which are related to that.

problem seems to be related to grouping by on columns with the same name in different tables


using OLEDB provider IBMDADB2.1

and the following SQL run from ReportBuilder


sect.name as Team,

tasktype.name as TaskType,










The SQL runs fine in a DB2 query tool but when run through ReportBuilder I get

[DB2/LINUXX8664] SQL0119N  An expression starting with "TASKTYPE" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified.  SQLSTATE=42803


Basically the problem seems to be related to grouping by on columns with the same name in different tables.

Anyone know a work around?

How do I create a query that joins two tables and returns a single entry with the most recent update


Say I have the following two tables (Purchase & Customer). 

CustomerID StoreName PurchaseDate
1 Asheville 9/14/2010 15:49

Insert/Update data to multiple tables on a single button click


Hi experts,

I need to insert/update data to 3 or more tables on a single button click.What is best method for achieving this?I am using mysql as my DB.

Thanks for your valuable reply in advance.

Update records related to primary table in sql


HI All,

For example

I have 2 tables  Person and Person_Child.

In Person table i have columns

Id, PersonId,PersonName,PersonAdrress,PersonAge,RowId


rowid is identity


and in the person_child table--here parentrowid refers to parent table rowid and again rowid is identity here

Id, PersonId,PersonName,PersonAdrress,PersonAge,ParentRowid,RowId




I need to update the child table values as it is in parent tables where it is null.

I have to do for many tables.

Is there any way to do it dynamically.







Using "Transaction activty" in Workflow to update 2 tables - throws "communication with the underlyi


I created a transactionscope over 2 code activities,
Code activity1 opens a connection, fires an insert into a table and closes the connection.
Code actibity2 also opens connection, does a simple insert into same table and closes the connection

I get the following exception:
The 1st code activity runs fine, then the second code activity fails when it tries to open a connection and I get this message "Communication with the underlying transaction manager has failed. "

I have persistence services working properly, I'm able to persist the workflows..which means my MSDTC is configured right, also able to insert data into the tables..but when I use the transactionscope I just get that error whever I open the connection in the second code activity

Am I missing something or this is one of those inbuilt bugs of the "workflowfoundation" bugs like the timer etc?

Update a table from two different tables


Hi there,

I'm working on SQL Server 2005.

I need to compare two tables and then update a third table depending on the comparison from two tables.

let's say I have Table A - the one I need to update

Table B and Table C. both of these tables have a common fieldname CustomerName, now when CustomerName from Table A and CustomerName from Table C are the same, I need to update Table A CustomerNameExist field with something like 'YES'

Let me know if I'm making sense here.




update two tables from single grid view using stored procedure PLZ help


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INV_DN
    public partial class Form1 : Form
        SqlConnection con;
        SqlDataAdapter da1;
        SqlCommand cmd;
        //  SqlCommandBuilder cb;
        DataSet ds;
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            con = new SqlConnection("User Id=sa;Password=123;database=amar");
            cmd = new SqlCommand("getdata", con);

Problems in deploying dimensions composed of related tables



I have a new dimension with attributes from different related tables but when I try to deploy it, I get the error message "Errors in the high-level relational engine. The table that is required for a join cannot be reached based on the relationships in the data source view." I checked the DSV and I have these tables with relations! What am I doing wrong?


Workflow is clearing a non related field upon update


Hello :)

I have a custom workflow in SPD that updates a field "Approved by" when another field "Review Date" = "today". This feature works fine, however at the same time, it clears the "Review Date" field, which is not what I want to happen. I don't have any actions in the workflow to clear the field, any ideas as to why this is happening? I can see that it happened at the same moment in the version history of the document.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend