How to combine two tables into a single datagrid

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 6
Reputation: sanjanaa is an unknown quantity at this point 
Solved Threads: 0
sanjanaa sanjanaa is offline Offline
Newbie Poster

How to combine two tables into a single datagrid

 
0
  #1
Oct 14th, 2009
Hi,

I have a dataset which is having 5 tables. I want to get only two tables from that dataset and assign into a single datagrid. How can i do this?

Thanks in advance...
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 45
Reputation: chandru7 is an unknown quantity at this point 
Solved Threads: 8
chandru7 chandru7 is offline Offline
Light Poster
 
0
  #2
Oct 14th, 2009
Try this Merge option,
ds.Merge(DataSet);

Splitting that two datatables in separate dataset.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 6
Reputation: sanjanaa is an unknown quantity at this point 
Solved Threads: 0
sanjanaa sanjanaa is offline Offline
Newbie Poster
 
0
  #3
Oct 19th, 2009
Hi Chandru, Thank you very much for your kind reply. I did that method, but in that my problem is, i have 3 rows, 8 columns in table1 and 3 rows, 8 columns in table2. First 2 columns of both the tables are same. Always i will get row count is same for both the tables. So, if i use this merge method then it creates a table with 6 rows, and also after the 8th columns has no values in first 3 rows and first 8 columns has empty values in second 3 rows.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 45
Reputation: chandru7 is an unknown quantity at this point 
Solved Threads: 8
chandru7 chandru7 is offline Offline
Light Poster
 
1
  #4
Oct 19th, 2009
Hi,

i will work if both structure's or same.For different structure just try like this,

  1. if(firstDataTable.Rows.Count > 0)
  2. {
  3. //Add all Coulmns and values to 3rd datatable.
  4.  
  5. }

In that same way Add second datatable to third.
Last edited by peter_budo; 33 Days Ago at 6:17 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 66
Reputation: reach_yousuf is an unknown quantity at this point 
Solved Threads: 12
reach_yousuf reach_yousuf is offline Offline
Junior Poster in Training
 
0
  #5
Oct 19th, 2009
Hello there

If i understand u correctly, u need a Nested/group dataset in a single dataset

Do the following, i have created an eg for you.
follow the steps
1) In solution explorer Add-> new Items -> Select "XML Schema"
2) Give the name eg : CommonDS Set
3) Go to the properities of "CommonDS" and Change Custom tool Property: MsDataSetGenerator
4) Right Click CommonDS -> View Code
5) Paste the following code Then change the Table NAme & Column names as per your requirement.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xs:schema id="CommonDS" targetNamespace="http://tempuri.org/CommonDS.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/CommonDS.xsd" xmlns:mstns="http://tempuri.org/CommonDS.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  3. <xs:element name="CommonDS">
  4. <xs:complexType>
  5. <xs:sequence>
  6. <xs:element name="Table1">
  7. <xs:complexType>
  8. <xs:sequence>
  9. <xs:element name="Col1" type="xs:string" />
  10. <xs:element name="Col2" type="xs:int" />
  11. </xs:sequence>
  12. </xs:complexType>
  13. </xs:element>
  14.  
  15. <xs:element name="Table2">
  16. <xs:complexType>
  17. <xs:sequence>
  18. <xs:element name="Column1" type="xs:string" />
  19. <xs:element name="Column2" type="xs:int" />
  20. </xs:sequence>
  21. </xs:complexType>
  22. </xs:element>
  23.  
  24. </xs:sequence>
  25. </xs:complexType>
  26. </xs:element>
  27. </xs:schema>

Pls. Mark as solved if it helps you
Yousuf
Software Developer
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC