0

HI

Can I join two data tables without any database connection,Please let me know if there way to do this.Iam using C#

Thanks
Tank50

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Tank50
0

HI

Iam reading from excel file and I store values into data tables.

Thanks
Tank50

0

HI

Iam reading from excel file and I store values into data tables.

Thanks
Tank50

You say that you want to store data from Excel file and store into two DataTable instances - You are going to split your data.

If you want to add relationship between two tables - one table must have a primarykey and another table must have a same datatype field in which relationship exists.

.....
 .....
 // Two DataTable instances
 DataTable dt1=new DataTable("Table1");
 DataTable dt2=new DataTable("Table2");

 dt1.Columns.Add("No",typeof(int));
 dt1.Columns.Add("Name");

 dt2.Columns.Add("No",typeof(int));
 dt2.Columns.Add("Data",typeof(int));

 // Adding a primary key
 dt1.PrimaryKey=new DataColumn[]{dt1.Columns[0]};

 // Create an instance of DataSet
 DataSet ds=new DataSet("DB");
 ds.Tables.Add(dt1);
 ds.Tables.Add(dt2);
 ds.Relations.Add("Relation1",dt1.Columns[0],dt2.Columns[0]);
 ...
 ...
0

Hi

I did what is adatapost is mentioned but problem its equi join,I want to join it as outer join ,coz if thre is no match record in dt1 table for dt2.Columns[0] then it give me exception.I want to join it as outer join.

Thanks
Tank50

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.