473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Joining 2 DataTables

hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!

May 11 '07 #1
7 2210
1. I would recommend doing it on database side if possible.
Use "UNION" in SQL to combine 2 SELECTs

2. If #1 is not an option, all I can come up with is manually adding rows
from one DataTable object to another DataTable object and then bind your
grid to that DataTable.

Like
DataTable dt1, dt2;
dt1 = GetData("...sql ...");
dt2 = GetData("...sql ...");

foreach(DataRow r in dt2.Rows)
{
DataRow newRow = dt1.NewRow();
newRow.ItemArra y = r.ItemArray;
dt1.Rows.Add(ne wRow);
}

George.

<Jo*****@gmail. comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!

May 11 '07 #2

<Jo*****@gmail. comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!
you might also look into dataset merge as long as you have a common primary
key defined. You would create a data set with the first table and then merge
the second table into the dataset.

May 12 '07 #3
I agree w/ George... and doing it on the DB side is the better
option. If using "UNION", be careful... you probably want "UNION ALL"
instead.

May 13 '07 #4
On May 12, 11:29 pm, GroupReader <newsgroups...@ hotmail.comwrot e:
I agree w/ George... and doing it on the DB side is the better
option. If using "UNION", be careful... you probably want "UNION ALL"
instead.
The union would not work unfortunately because it is using the same
database.
It is completely dependant on what the user actually inputs into the
screen as to what I am adding to the grid.
Basically there are 2 distinct types on data for the grid, and they
can't be mixed up. So I was just going to create separate datatables
and then merge them together.
It seems like I will have to just try the looping or the merge
method , because I don't think that it will work any other way
really.
Thanks guys!

May 14 '07 #5

DataSet.Merge works well.

---------------
IF you have 2 seperate tables (in your dataset) .
Like
ds.Employee
ds.Dept
-----------
It works well on one table, but you have different PK's (as mentioned)

like
ds.Employee
ds.Employee
(perhaps the first one has full time employees, and the second
one has part time employees)
EmployeeDS ds1 = new EmployeeDS();
//populate ds1 with full time emps.

EmployeeDS ds2 = new EmployeeDS();
//populate ds2 with parttime emps.

EmployeeDS dsmerged = ds1.Merge( ?? ds2 //multi overloads here) ;
...

Merging "the same rows based on the PK" is a totally different story, and
this permutation doesn't play nice.

<Jo*****@gmail. comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!

May 14 '07 #6

"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.comwr ote in message
news:DT******** ******@bignews7 .bellsouth.net. ..
>
<Jo*****@gmail. comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
>hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!
you might also look into dataset merge as long as you have a common
primary key defined. You would create a data set with the first table and
then merge the second table into the dataset.
The more I think of it you can merge two or more tables as a union or as a
left join, depending on the MissingSchemaAc tion. The merge function will
union if the two tables have identical structure but if there are any
duplicate primary keys it will fail. If you want to join you would need
identical primary keys in both tables and use the msa.add.

Mike
May 15 '07 #7

"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.comwr ote in message
news:Yk******** ********@bignew s4.bellsouth.ne t...
>
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.comwr ote in message
news:DT******** ******@bignews7 .bellsouth.net. ..
>>
<Jo*****@gmail .comwrote in message
news:11******* *************** @q75g2000hsh.go oglegroups.com. ..
>>hey guys,
I'm a little new when it comes to the ASP environment, and I need a
little help...
Does anyone know how to combine two separate datatables, and get them
to display one after the other on a datagrid? I am currently trying to
use viewstate.Add, to get both of them together but that's just not
working, and I don't see a viewstate.merge or join or anything.
Has anyone ever found a way to work around this? Or is there something
I am overlooking?

Thanks!
you might also look into dataset merge as long as you have a common
primary key defined. You would create a data set with the first table and
then merge the second table into the dataset.
The more I think of it you can merge two or more tables as a union or as a
left join, depending on the MissingSchemaAc tion. The merge function will
union if the two tables have identical structure but if there are any
duplicate primary keys it will fail. If you want to join you would need
identical primary keys in both tables and use the msa.add.

Mike
I got the fail backwards. The left join will fail if there are more then one
identical primary keys in the left join table. Merge will fail for one to
many, has to be one to one. The union will ignore the identical key.
May 15 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2056
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables automatically?? Will the integrity rules automatically be enforced or do i need to recode this in vb.net? Also do the datatables created have the same...
4
4254
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 to join these tables on the basis of Date. I don't want three rows for each date, i want the values to be added for similar dates. thanx
2
4323
by: Z D | last post by:
Hello, I'm currently using Remoting (HTTP/Binary) to remote a simple object. Everything is working fine except for one function that returns an arraylist of datatables. When I call this function, nothing is returned (ie length of array =0). However, if I comment out my config file so that the DLL is run locally instead of remoting it,...
4
2251
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 will work with a variable mutl- row, 5 column datatable where the users select items. Anyone have any suggestions on where to start? Or changes in...
5
13348
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 appropriate items in a checkedlist box are selected based on the dt. So far, no problem. Then user can then edit the values in the checkedlist box and...
3
1582
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they fit into the picture. I'm going to be reading some records from a table in a sql db.
3
2445
by: bbdobuddy | last post by:
Hi, I have two datatables that I want to left outer join and then do some queries on but I having a hard time figuring out how to join the datatables together. One of the datatables comes from a sql database and one comes from an .dbf file Any help would be greatly appreciated Thanks
0
1515
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)? I currently have 2 datatables in the dataset. The first one contains the header records with columns such as Id, DateCreated, DateModified, etc The...
2
1915
by: =?Utf-8?B?QVZM?= | last post by:
Hi, Ive two data tables..I need to perform a join on these datatables.. and fetch the data..I need to do it programaticlaly.. How can I acheive it...any sample code wpuld be of great help..
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.