Click here to Skip to main content
14,691,771 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

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

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;

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!!
Sushil Mate 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 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 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 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 29-Jan-13 9:08am
very well. you are welcome.
P_Dash 28-Jan-13 7:20am
Plz write the SQL Query what you have used for Merging purpose.
P_Dash 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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900