LINQ - Making input query VS2008 - Asked By David on 07-Feb-11 04:21 PM

 I am not sure if LINQ is the right category but my question is this

 I have 2 DataSets/Tableadapters with 1 table in each ie: Table1 Table2
 I want to run an insert or add query from Dataset1 which adds all 38 rows from Table1 into Table2 which has 164 rows
 of which 38 are the same name.
How do I join the Tables and make it do this in the criteria pane

Peter Bromberg replied to David on 07-Feb-11 04:50 PM
Have a look at the Merge method on the DataTable class.
Mash B replied to David on 08-Feb-11 01:26 AM
As peter said above , The Merge method is used to merge two DataSet objects that have largely similar schemas.

You can use below code for your solution

Dataset ds1 = new Dataset;  // you have table1 here
Dataset ds2 = new Dataset;  // you have table2 here
ds1.Merge(ds2); // ds1 will incorporate all unique records from table1 to table2
David replied to David on 08-Feb-11 04:59 AM

  Hi Mash

 I am getting faults which are under lined or in red
 I am trying to select 1 row only by using a dataview form and selecting the primary key number this works on a delete form I set up using the primary key as the filter (?) and this I set in the DataSet Delete Command text.
 Now I am trying to select 1 row in the same way to merge from CourseDataSet1 (table = Course ) into CoursesPlayedDataSet (table = Courses played)

Using the code below to insert

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

      CourseDataSet1 = New CourseDataSet1; COURSE

     CoursesPlayedDataSet  = new CoursesPlayedDataSet ;// COURSES_PlAYED

      CourseDataSet1 .Merge(CoursesPlayedDataSet); //  
    End Sub

 Thanks David

Mash B replied to David on 08-Feb-11 12:27 PM
As i said both the schema of dataset should be same, ie. Number of columns and datatype should be same of both dataset in order to merge data. If both schema are different then you need to copy data manually by looping through data in dataset.
Subhashini Janakiraman replied to David on 11-Feb-11 03:46 AM
Here is my code for one to one relationship between the tables with datasets DataSet1 and DataSet2.

DataSet1DataContext dat1=new DataSet1DataContext();
DataSet2DataContext dat2=new DataSet2DataContext();
var table3=from d in dat1.Table1 
         from c in dat2.Table2
         where d.parentid=c.parentid
         select new
foreach(var r in table3)
Response.Write(r.col1.ToString()+""+ r.col2.ToString()+"  "+ r.col3.ToString()+"  "+ r.col4.ToString()+"  "+ r.col5.ToString());