954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Join Two data tables

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

Tank50
Junior Poster
124 posts since Aug 2008
Reputation Points: 12
Solved Threads: 1
 

Where are you getting the Data From??

extofer
Posting Whiz in Training
239 posts since Aug 2005
Reputation Points: 8
Solved Threads: 6
 

HI

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

Thanks
Tank50

Tank50
Junior Poster
124 posts since Aug 2008
Reputation Points: 12
Solved Threads: 1
 

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]);
 ...
 ...
__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

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

Tank50
Junior Poster
124 posts since Aug 2008
Reputation Points: 12
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You