Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DataTable
Hi,
 
I am trying to merge two completely different datatables to a single datatable i am able to merge them but in the final datatable i am bnding to the grid view ... the values are fetching but it is showing output like this.... for ex:
 
Col1 Col2
- --- Name
- --- Class
- --- Animal
- --- Value
1
2
3
4
 
i am getting blank spaces ... there is no common field between two datatables so what should i do to resolve this issue please let me know... my coding for merging is as follows:
 
            DataTable dtAll = new DataTable();
            dtAll = score1.Copy();
            dtAll.Merge(newdt, true);
            grdscore.DataSource = dtAll;
            grdscore.DataBind();
 
Please help me resolve this issue i tried many ways like deleting off empty cells and also like ading a common field to both datatables.. but all that did not work...
 
Thanking you in advance!!
Posted 28-Jan-13 0:00am
Comments
Sushil Mate at 28-Jan-13 6:20am
   
why don't you use the sql query for merging the two tables together & the result will be single merge table which you can bind to data grid.
Shruthi.BT at 28-Jan-13 6:30am
   
the values for one datatable i am getting from Excel sheet and the other datatable values i am getting from database so.. i am not able to merge them like any other normal table with unique ids so how do i merge the datatables... is there any way i can merge them without any blank spaces... please help...
Sushil Mate at 28-Jan-13 6:34am
   
why this is happening because of the column is different. there has to be same columns in both tables when we are merging two tables together. otherwise it will put null values when it don't find the values in other table for that column. this is what happening in your solution.
Shruthi.BT at 29-Jan-13 8:19am
   
thanks.. for reply... i tried it without the common id so was not able to merge... but the solution i tried to combine the tables and used a single table... thank you...
Sushil Mate at 29-Jan-13 9:08am
   
very well. you are welcome.
Gittu Dash at 28-Jan-13 7:20am
   
Plz write the SQL Query what you have used for Merging purpose.
Gittu Dash at 28-Jan-13 8:28am
   
Dude, why don't you create a Stored Procedure for Retrieving data from both the tables using Join in SQL Server ?
 
I think since you are merging the tables in fron end instead of back end, so you are getting this problem.
You better merge or Join the 2 tables in Back end & just retrieve data in Front end.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,696
1 Sergey Alexandrovich Kryukov 6,675
2 CPallini 5,315
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100