943,920 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4649
  • C# RSS
May 5th, 2009
0

Join Two data tables

Expand Post »
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
Similar Threads
Reputation Points: 12
Solved Threads: 1
Junior Poster
Tank50 is offline Offline
124 posts
since Aug 2008
May 5th, 2009
0

Re: Join Two data tables

Where are you getting the Data From??
Reputation Points: 8
Solved Threads: 6
Posting Whiz in Training
extofer is offline Offline
239 posts
since Aug 2005
May 5th, 2009
0

Re: Join Two data tables

HI

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

Thanks
Tank50
Reputation Points: 12
Solved Threads: 1
Junior Poster
Tank50 is offline Offline
124 posts
since Aug 2008
May 5th, 2009
0

Re: Join Two data tables

Click to Expand / Collapse  Quote originally posted by Tank50 ...
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.

C# Syntax (Toggle Plain Text)
  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. ...
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
May 6th, 2009
0

Re: Join Two data tables

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
Reputation Points: 12
Solved Threads: 1
Junior Poster
Tank50 is offline Offline
124 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Problem with public interface
Next Thread in C# Forum Timeline: installation problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC