Join Two data tables

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 94
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Join Two data tables

 
0
  #1
May 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 239
Reputation: extofer is an unknown quantity at this point 
Solved Threads: 5
extofer's Avatar
extofer extofer is offline Offline
Posting Whiz in Training

Re: Join Two data tables

 
0
  #2
May 5th, 2009
Where are you getting the Data From??
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 94
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Re: Join Two data tables

 
0
  #3
May 5th, 2009
HI

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

Thanks
Tank50
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 464
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Join Two data tables

 
0
  #4
May 5th, 2009
Originally Posted by Tank50 View Post
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.

  1. .....
  2. .....
  3. // Two DataTable instances
  4. DataTable dt1=new DataTable("Table1");
  5. DataTable dt2=new DataTable("Table2");
  6.  
  7. dt1.Columns.Add("No",typeof(int));
  8. dt1.Columns.Add("Name");
  9.  
  10. dt2.Columns.Add("No",typeof(int));
  11. dt2.Columns.Add("Data",typeof(int));
  12.  
  13. // Adding a primary key
  14. dt1.PrimaryKey=new DataColumn[]{dt1.Columns[0]};
  15.  
  16. // Create an instance of DataSet
  17. DataSet ds=new DataSet("DB");
  18. ds.Tables.Add(dt1);
  19. ds.Tables.Add(dt2);
  20. ds.Relations.Add("Relation1",dt1.Columns[0],dt2.Columns[0]);
  21. ...
  22. ...
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 94
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Re: Join Two data tables

 
0
  #5
May 6th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC