473,406 Members | 2,633 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.

Merging two Datatables into a Matrix style Datatable.

2
Hi,

I have a situation where I need to take multiple DataTables and
convert them to a single Datatable which would be simple if I didn't
need to convert them into a matrix where like items will be combined.
For example say I have 3 DataTables like so:

Note all three datatables have the same fields. They are:
Qty, CatalogNo, Part, Description, length, width

DataTable1 with comma seperated field values:
1, Q123456, 01, Limit Switch, 0, 0
1, E654321, 02, 1/2" Bolt, 0, 0
8, F786543, 03, 3/4" Bolt, 0, 0
1, P967349, 04, 1/2" Stainless Plate, 13, 14
1, P967349, 05, 1/2" Stainless Plate, 123, 48

DataTable2 with comma seperated field values:
1, Q123456, 01, Limit Switch, 0, 0
1, E654321, 02, 1/2" Bolt, 0, 0
8, F786543, 03, 3/4" Bolt, 0, 0
1, P967322, 04, 1/2" Carbon Plate, 13, 14
1, P967322, 05, 1/2" Carbon Plate, 123, 48

DataTable3 with comma seperated field values:
1, Q123456, 01, Limit Switch, 0, 0
3, E654321, 02, 1/2" Bolt, 0, 0
8, F786543, 03, 3/4" Bolt, 0, 0
1, P967349, 04, 1/2" Stainless Plate, 13, 14
1, P967349, 05, 1/2" Stainless Plate, 123, 48


These tables would be then converted into a table with the fields:

Qty03, Qty02, Qty01, CatalogNo, Part, Description, length, width

And have the comma seperated field values of:
1, 1, 1, Q123456, 01, Limit Switch, 0, 0
3, 1, 1, E654321, 02, 1/2" Bolt, 0, 0
8, 8, 8, F786543, 03, 3/4" Bolt, 0, 0
1, 0, 1, P967349, 04, 1/2" Stainless Plate, 13, 14
0, 1, 0, P967322, 04, 1/2" Carbon Plate, 13, 14
1, 0, 1, P967349, 05, 1/2" Stainless Plate, 123, 48
0, 1, 0, P967322, 05, 1/2" Carbon Plate, 123, 48

I realize this isn't really clear but I hope someone can follow what
I'm trying to do. I'll take any help I can get.

Thanks,
Tim
Dec 5 '07 #1
2 1730
Plater
7,872 Expert 4TB
Well I don't know of a "nice" way of doing it, only the long way.
Create a DataTable with your desired columns.
Loop through each DataTable, inserting (or updating) their values into that new DataTable.

EDIT:
Actually, I think you can do this with some fancy SQL, if you can call a SELECT statement to reference all three datatable at once and use a GROUP BY clause, you should be able to do it.

Something in the idea of this:
Expand|Select|Wrap|Line Numbers
  1. SELECT t1.qty as [QTY1], t2.qty as [QTY2], t3.qty as [QTY3], <"other categories"> FROM t1, t2, t3 GROUP BY <"whatever it is that you would use to combine entries">
  2.  
Dec 5 '07 #2
riltim
2
Thanks for the reply. I figured I would have to go about it the long way to combine all this data. I would take the SQL approach but I'm not pulling this information from a database, I'm loading the table from an XML string I am reading and writing to a file.
Dec 5 '07 #3

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...
2
by: Phil Townsend | last post by:
I am working in a web app that contains two datasets that are cached. I would like to pull the first table from each dataset and put each into a single dataset, so as to have a single dataset with...
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: Thanya Teutschbeim | last post by:
I'm trying to use DataSet.Merge, but it works like an Append, and I don't want this. I want to update dataset data. I have two files with same fields and the same xml schema. For example: File...
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...
1
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, do you know a simple way how to merge two datatable that kind, that both divide the same data row? I've got a DataTable with only one data row and another DataTable with only one data...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.