473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to combind two datatables in to one datatable in .net

139 100+
Hai All,

I need to combind two datatables.First table contains 2 columns and 2nd table contains 3 columns, i need to combind both in one table, and the result should be in 5 columns.Is it possible...?


Thanks,
Aswath.
Jan 2 '08 #1
12 2692
mzmishra
390 Expert 256MB
yes it is possible.
Create third table have all 5 columns and populate the data with both the tables.
Jan 3 '08 #2
debasisdas
8,127 Expert 4TB
you need to combine two databases or two tables ?

BTW what is the database that you are using ?
Jan 3 '08 #3
bhappy
139 100+
Hai
Thanks for Replay,

Im using MS SQL Server.Im getting data from Database,In code behind im using two datatables for two stored procedures.finally i need to combind two datatables to one and i want the result in pyarlally ie.
datatable1 --10 rows x 2columns
datatable2 --10 rows x 3 columns

result table:---- 10rows x 5 columns is it possible.....?

Thanks,
Aswath.
Jan 3 '08 #4
kunal pawar
297 100+
u can do it, just create table using Datatable, Datacolumn and then add the both tables rows in 3rd table
Jan 3 '08 #5
bhappy
139 100+
Hai

Thanks for Replay,
Creating new datatable is ok,but while adding rows from two datatables i dont't have any common columns,how can i add..? and i tried like using "datatable.loaddatarow()" method but im getting result as

dt1-----10 x 2 (rows x columns)
dt2 ----10 x 3

for i=0 to dt2.rows.count-1
dt1.loaddatarow(dt1.rows(i).itemarray,true)

output is :dt1--------20 x 3
need dt1 as 10 x 5 (rows x columns)

Thanks,
Aswath.
Jan 3 '08 #6
bhappy
139 100+
Hai All,

Any sollution to my problem..................?

Thanks,
Aswath.
Jan 3 '08 #7
Create Datatable with 6 columns

1 Column should have a unique field which is used to update the datas from second database table.

Query the first Database and create the rows through code.

query the second Database and compare the each and every row compare with datatable and update the 3 columns in datatable.

You will get 6 column Datatable. If you wants to bind with anyother control just make visible false it the unique id column.
Jan 3 '08 #8
Hai
Thanks for Replay,

Im using MS SQL Server.Im getting data from Database,In code behind im using two datatables for two stored procedures.finally i need to combind two datatables to one and i want the result in pyarlally ie.
datatable1 --10 rows x 2columns
datatable2 --10 rows x 3 columns

result table:---- 10rows x 5 columns is it possible.....?

Thanks,
Aswath.
without having common column in those you can't combine those two tables
using views you can get that type of results
Jan 3 '08 #9
CyberSoftHari
487 Expert 256MB
Can you explain why you want to combine two tables? That will be helpful to the experts to point you correct direction.
Note: do not let us assume
Jan 3 '08 #10
bhappy
139 100+
Hai

Thanks for Replay,

I already told that there is no common columns in two tables, so im using two datagrids(side by side) to display the information.Up to here it is ok,Now my client need the data to be exported to Excel.Here im getting problem that only one datatable data is exported to excel.That's why i need to combind two datatables.

Thanks,
Aswath.
Jan 3 '08 #11
balabaster
797 Expert 512MB
Hai

Thanks for Replay,

I already told that there is no common columns in two tables, so im using two datagrids(side by side) to display the information.Up to here it is ok,Now my client need the data to be exported to Excel.Here im getting problem that only one datatable data is exported to excel.That's why i need to combind two datatables.

Thanks,
Aswath.
I would probably just do a straight parse of the two datatables...
  • Create an instance of an Excel Workbook/Worksheet
  • Parse table 1 dumping the contents into columns 1 and 2 of the worksheet instance
  • Parse table 2 dumping the contents into columns 3, 4 and 5 of the worksheet instance
  • Save the worksheet object to disk
  • Dispose the worksheet object
Does that answer your question? You specify that you don't have any piece of common data, but the way you describe it, there is a tacit implication that the row number of each grid is the common key. Even though neither grid physically contains a key field, the key is implied in the manner in which you are wanting to join the tables.

Table1.Row0 is paired with Table2.Row0
Table1.Row1 is paired with Table2.Row1
Table1.Row2 is paired with Table2.Row2
etc...

Your common piece of data is the row number of each data table, even though it is not contained within the visible data sets.
Jan 3 '08 #12
bhappy
139 100+
Hai
Thanks for Replay,
i dono how to parse datatable to excel.any other idea plz.........?
Jan 4 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Job Lot | last post by:
Is there anyway of Joining two or more DataTable with similar structure? I have three DataTables with following structures Data, AmountB/F, Repayments, InterestCharged and AmountC/F i want...
2
by: Jenny K | last post by:
Hi everyone, I've got a console application that grabs data into 3 datatables asynchronously, and writes each datatable's data to a textfile. The problem is that the data returned by each sproc...
1
by: psb | last post by:
I thought this was weird?? is this a bug in framework 1.0??? (1.0 is the version I am running against) --------------------------- dim dtAll as new datatable dim dtTmp as datatable dtTmp =...
1
by: Gene Ariani | last post by:
I have one dataset that contains two DataTables: DataTable1: Customer_ID 1
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
9
by: DraguVaso | last post by:
Hi, I have two DataTables (our DataViews or whatever that will suit the best for the solution). I want to merge these two DataTables the fastest as possible, but they have to be merged one table...
5
by: Frank | last post by:
Hello All, I am working on a vb.net app where I need to compare to 2 datatables and determine if a string exists in one or both. The first dt is filled from the db. A form is loaded and the...
2
by: MarkusJNZ | last post by:
Hi, I have a DataTable which I want split into two other datatables with the top 1/2 of the original datatable in one datatable and the other 1/2 in another datatable. Is there any easier way to...
0
by: StefanPienaar | last post by:
Hi Guys Is there any way in c# (or vb.net) to extract a datatable of data from a dataset with multiple datatables which has relationships set up (containing combined data from the datatables)? ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.