.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

Inserting data in multiple tables C#

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

Hi! Is there any way I could insert a record in multiple tables using only a single post? So far I could insert records in a single table using formsview and detailsview but it only allow me to insert records in one table. I have 4 tables and each has foreign keys and dependencies with other tables.

Any help will be appreciated.


View Complete Post

More Related Resource Links

Excel data into multiple tables

Hi,       I  have excel file with columns EmpName,Date1,Date2,...Date7 .I want to insert EmpName into Employee table after inserting i will get EmpNo(Identity column) with that  i need to insert Date1,Date2...Date7 into TimeSheet table.    My Excel structure is like this EmpName  8/1/2010      8/2/2010     8/3/2010       8/4/2010    8/5/2010    8/6/2010 8/7/2010 Naresh    17:00-2:00   17:00-2:00   14:00-12:00  7:00-12:00  7:00-12:00  ..               Off Similarly 500 employees data I want to insert name i.e into Emp table after inserting i will get EMpNo i.e identity column with that i should insert Date1(8/1/2010) i.e excel header to date7 into Timesheet table Date column and corresponding time into TimeIn and TimeOut.I will split the time.I just want write Stored procedure for this task. My database tables are like this Emp-EmpNo,EmpName,CompaignId Timesheet-TimeID,EMpNo,Date,TimeIn,TimeOut,TotalHours   Date in Timesheet should be like this   TimeId     EmpNo     Date       TimeIn     TimeOut 

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.

Data Flows in SSIS - Mapping Multiple source tables to Destination table **Newb question**

Hi I am new to SSIS and had a basic question. I have around 30+ tables in a db that needs to be migrated to a newer schema in the DB. The data flow task seems to be ideally suited for my requirement. My question is do I need to create 30+ different data flow tasks for this which will get executed one after the other or is there a better way to migrate large number of tables. Also how are referential constraints taken care of during such migration. Thanks and Regards, Ganesh Ranganathan
Ganesh Ranganathan
[Please mark the post as answer if it answers your question]

Inserting values into multiple tables (using SCOPE_IDENTITY)



I have problem inserting multiple values into multiple tables from web form. I have a web form for creating article (from table Clanak) and in the end there is a textbox (txtTagovi) that is used for inserting Tags (in table Tagovi) which are separated by ";".

These are the tables: Clanak (idClanak,...), Tagovi (idTag, naziv) and the cross reference table ClanakTagovi (idClanakTagovi, idClanak, idTag)

There are multiple problems...

The first one is how to get the SCOPE_IDENTITY (without stored procedures) of the last inserted Article (from table Clanak) without getting the following error: "Incorrect syntax near ')'." I will comment the part of the code that has this problem.

The second problem is implementation of the tags. I am aware that if my current solution gets corrected it won't be what I originally wanted because my idea was to add tags and if there are similar tags I wanted them to get the same ID, without having duplicates in table (that's why I need Clanak Tagovi table).

For example:

Clanak {(idClanak=1,...),(idClanak=2,...),...}, 

Tagovi {(idTag=1, naziv="Tag1"), (idTag=2, naziv="Tag2"), (idTag=3, naziv="Tag3"),..} , 

ClanakTagovi {(idClanakTagovi=1, idClanak=1, idTag=1), (idClanakTagovi=2, idClanak=1, idTag=2), (idClanakTagovi=3,

Dynamic Data, Multiple Tables in one page?


Hi there,

So I have a Dynamic Data Project with a few custom pages that are not the standard list/insert/update pages. So I created my custom page, Process.aspx. It's a regular web form with a dynamic data manager, plus a LINQDATASOURCE. That works fine. However, inside of my main formview I'm going to have a subformview. So I set up a second LINQDATASOURCE, but it seems when I try and use Dynamic Data Controls inside of my sub form view, it can't seem to find the MetaTable, even though I set the subformview up with its own data source. Can I have two dynamic data managers somehow, one for each data source? I don't think there's a way to associate a dynamic data manager to a specific data source, as far as I can tell.

Or, can I do something like :

<asp:DynamicControl runat="server" DataField="Client.SubField" />

Any insight is appreciated!

Storing XML data in multiple related tables at one shot


Hi, I am looking for some ways to store data in multiple related tables in one shot using the advanced features in SQL Server 2005. The store operation will always be the insertion into the different but related tables.


The scenario is something like this. I have an input XML data, on which I apply XSLT to convert them in relational format and to make it compatible with a dataset schema which I created from the related tables from the database. Then I load the refined XML data into a dataset. I am looking out for some ways to store the dataset in one shot into the database in relational format without breaking records parent-child relationship. Thanks in advance for your suggestions and feedback.


Selecting data from multiple tables whilst using a union statement.



any help on this would be great.

I basically have a series of tables from one database that have an identical structure thus making retrieval of all records fairly easy (I just use a UNION ALL statement). However I need a list of values from another table within a different  database that contains information regarding the group of the data.

I so far have the following:

SELECT Table1.* FROM Table1 UNION ALL SELECT Table2.* FROM Table2 UNION ALL SELECT Table3.* FROM Table3 UNION SELECT Database.dbo.SRFILE.SR_GROUP FROM Database.dbo.SRFILE INNER JOIN Database.dbo.SRFILE.SRONUMBER = Table1.Incidentx

I keep receiving a unable to parse message however all I need to retreive is the SR_GROUP value but just don't know the correct syntax. Is it actually possible to do this as the structure of SRFILE is not the same as Table1/2/3.

Thanks again,


MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

merging multiple tables in a single dataset to single table


 i have a stored procedure which returns three tables to a dataset ..... now i need to merge all three tables to a single table from d same dataset 

like dataset1 has table1 table2 and table3 .... i want all the three tabels to be merged into dataset1 itself .... instead of three diffrent tables so that i can show all three table data in a single datagrid  as a compact data and combination of 3 tables from d single dataset.....

can some1 help me please.....

Inserting data to ExcelSheet


Hi all,

I have a web form, in that i'll enter daily expense details.

After i press save button, the data i entered are saved into an excel sheet.

I don't have idea how to save the data to excel sheet, so your help for this greatly welcome. 

Reading data from .doc or .docx and inserting into db



A vendor is providing content which needs to be inserted into the db. The content is basically questions with options and explanations. An example is below.


data from multiple row



I have a dataset in my SSRS report where I am getting the data like this. It has 3 rows.

ID Parameter Value

1. Client Name-  XYZ

2. Client Email - xyz@s.com

3. Clinet Phone- 234567

I need to check condition in expression, so If parameter is Client name then It will show in client name textbox of Report. How can write expression for this.

Data Points: Creating Audit Tables, Invoking COM Objects, and More


Dealing with error handling between T-SQL and a calling application, evaluating when a field's value has changed, and creating auditing tables in SQL ServerT are all common issues that developers must tackle.

John Papa

MSDN Magazine April 2004

How do you create a custom BDC data field that allows for multiple selected values?

I need help creating a custom data field using the BDC column as a base.  We need to allow for multiple selected values instead of just a single one.  I can't find anything on the net which shows how to do this.

Creating .NET Assemblies That Aggregate Data from Multiple External Systems for Business Connectivit

This article describes a quick, four-step process for creating a .NET assembly that BCS can use to retrieve external data for SharePoint Server 2010 by using Visual Studio 2010.

Using the single *.rpt file with multiple data sources


I've created a set of CrystalReports (*.rpt files) for an ASP.NET web app on a development server. I call each report using the following code:

protected void BTN_RunReport_Click(object sender, ImageClickEventArgs e)
CrystalReportViewer_ClientLetter.Visible = true;

ConnectionInfo con = new ConnectionInfo();
con.ServerName = Constants.ServerIP;
con.DatabaseName = Constants.DatabaseName;
con.UserID = Constants.UserID;
con.Password = Constants.Password;

CrystalReportViewer_ClientLetter.ReportSource = Server.MapPath(Constants.ClientLetters);
ParameterFields parameter = CrystalReportViewer_ClientLetter.ParameterFieldInfo;
ParameterField batchdate = new ParameterField();
batchdate.Name = "@BatchDate";
ParameterDiscreteValue batchdate_value = new ParameterDiscreteValue();
batchdate_value.Value = Convert.ToDateTime(txtBatchDate.Text);

foreach (TableLogOnInfo tlf in CrystalReportViewer_ClientLetter.LogOnInfo)
tlf.ConnectionInfo = con;

Data flow task with multiple destinations randomly hangs

I have a package whose control flow consisting of a single data flow task with multiple destinations continues to hang at random locations.  The data flow task is fairly simple: - One OLE DB source (one query of selecting about 10 fields from one table) - 9 lookups that serve basically as left joins to capture which data "drops off" (does a row redirect on on lookup errors to an "error flow") - Two destinations: one the captures all the data that doesn't drop off from the lookups, and another to capture the data that does drop off; these write to two tables unrelated to each other, and unrelated to any of the tables I'm reading from I have tried the following: - Changed one or both destinations from OLE DB to flat file -- still randomly hangs - Removed both destinations altogether -- this always suceeds.   - Removed destination A and leave destination B -- this always succeeds - Removed destination B and leave destination A -- this always succeeds I took great care in making sure I get no warnings when the package runs, even resolving the unneeded column warnings, and the duplicate keys on all my lookups, but it still hangs. However, once I give up and stop the package, the following error is thrown (among others that appear to be a byproduct of the root issue): Error: 0xC02020C4 at Data Flow Task, OLE_SRC AP12 [1]: The attempt to
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