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

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

Event Hanlder to update other SQL tables

Posted By:      Posted Date: August 24, 2010    Points: 0   Category :ASP.Net


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 =

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>

Update related tables

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

event receiver to update created field of uploaded document

Hi,   I need to update the created column with the document creation time . 1) First should i use ItemAdding event or Item Added event 2) how do i get the file created properties and assign it to the cdocument library created column.

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 

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.

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.




Gridview update event not firing


Everything is working fine on my gridview except the Update.  When I click on the Update link, nothing happens.  I've researched the problem and tried various solutions I've seen, but no luck.  I'm hoping someone else can see something that I'm missing. 

<asp:GridView ID="grdAddInsured" runat="server" DataSourceID="dsUnitAdditionalInsured" DataKeyNames="AddInsuredID"

AutoGenerateColumns="False" ShowFooter="True" Width="

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);

Is it possible to update a list item in the ItemUpdating event receiver?


i need to add a property (SPListItem.Properties) to the SPListItem being updated in my ItemUpdating event receiver. is there any way to do that?

SPListItem.Update() doesnt seem to be an option, so the obvious answer is probably trying to use the SPItemEventProperties object called properties by calling properties.AfterProperties.ChangedProperties.Add(key, value) and letting sharepoint do the rest, but it turns out it actually deals with fields and not properties. it's a little misleading. so is there another way? some kind of painful work around maybe?

Update datagrid and Event-Based Async calls


I’m using a datagrid (actually Infragistics XamGrid) which is bound to a custom list of business objects.  In the old WPF days, when completing the edit of a grid row, the business object’s EndEdit() method would be called via databinding.  The EndEdit() method would then save the data to the db via a web service call.  The retuning result of the web service call would tell the business object (in the EndEdit() method) of the call succeeded or failed.  If it failed, it would roll back the changes and raise an event to alert the UI.

In the world of Silverlight and Event-Based Async calls, it’s not possible to do all of this from in the EndEdit() method.

Also, I’m generating my web services using the SLsvcUtil.exe tool.  Since MS is forcing us to use Async calls, then what is the standard way to update data from a gird row and then roll it back and alert the UI when the call fails?

I found a nice article http://blog.jayway.com/2010/06/10/silverlight-prefer-synchronous-web-service-calls/ about making synchronous web service calls in SL, but the catch is that can’t be on the UI thread which – updating a gird row will be on.

Please relay any advice and resources you can offer!


TextBox within DataTemplate for ContentPresenter not triggering update event


I have designed a complex DataTemplate to re-use among several ContentPresenters I have on a dialog. Within this DataTemplate I have a TextBox that is bound to a DependencyProperty of a custom UserControl. I'm having trouble setting the binding correctly to get updates reflected in my viewmodel. Setting the TextBox text from the property value works correctly, but not the other direction, updates when the user changes the text are not updating the source. I've created a small sample program to illustrate the issue.


<Window x:Class="TestBinding.MainWindow"
    Height="203" Width="223">
    <DataTemplate x:Key="CustomUcTextBoxTemplate">
        <Grid >
          <TextBox x:Name="testTextBox" Height="28" 
            Text="{Binding Path=Title,
               RelativeSource={RelativeSource FindAncestor, Ancest

Update table - based on result of 2 columns from other tables


MSSql 2008 (2000 state)

Trying to update a column in a mapping table based on if the mapping is correct.

Table 1 own car data (PK model_ID)
Table 2 external cardata (PK Styr_ID)
Table 3 User mapping between Table1 and Table2 (PK's model_ID and Styr_ID)

I have made quite a big SQL joining data from Table 1 and Table 2 to verify if mapping is correct - And I have retrieved all incorrect rows that needs to be updated in table3 - Succes... Now I need to update Table 3 based on these results..
- The result is 3500 rows containing both model_ID, Styr_ID (these I have inserted in a temp_table - Both it didn't help me out..)

The problem I can't figure out, is that I need both values to find the correct row and update it in table3..
The only way I can see it done, is by selecting twice - but then it's not nessesary that the values are from same row (i actually doubt that they ever are)

Update table3 set status = 'A' where ......   select model_ID, select Styr_ID

The number of calls to the Changed event for a single update in the data exceeded the maximum limit.


Dear All,

We have hit the big limit of 16 change events per single update.  Is there any way to extend this to say 25, we are not using infinate loops or anything.

Alternatively, is it possible to disable some change events when values are updated?


William Man

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

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