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


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

c# ADO.NET

Posted By: Ilkin     Posted Date: March 28, 2013    Points:5   Category :C#
Hello.

Below I showed my example where i try to add first table field values to secodn table. According to second table column name.Want to say , if first table FIELD_ID = second table column name then add.if any idea help please

DataTable dt = new DataTable();
dt.Columns.Add("Field_ID", typeof(Int32));
dt.Columns.Add("Field", typeof(String));
dt.Rows.Add(new object[] { 1, "Masin" });
dt.Rows.Add(new object[] { 2, "Tank" });
dt.Rows.Add(new object[] { 3, "Helicopter" });

DataTable dt2 = new DataTable();
dt2.Columns.Add("1", typeof(String));
dt2.Columns.Add("2", typeof(String));

Thanks in advance.

Responses
Author: Narayanan             
Posted Date: April 01, 2013     Points: 20   

Hi ,
AS my Understand, you want to add One Data Table into another Data Table that means you want to Copy the Data from one table into another table

try this Code:

foreach (DataRow dr in dataTable1.Rows) {
if (/* some condition */)
dataTable2.Rows.Add(dr.ItemArray);
}


Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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