473,598 Members | 3,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining Rows

How can I easily add the rows of DataTable1 to the rows of DataTable2. Both
queries are from the same table. I can always use the column names with
myRow["name"], but I was wishing for a shortcut. When I try this it doesn’t
work.

for (int i = 0; i < dataTable1.Rows .Count; i++)
{
myRow = dataTable2.NewR ow();
myRow = dataTable1.Rows[i];
dataTable2.Rows .Add(myRow);
}
return dataTable2;

Jul 21 '05 #1
3 2778
Look at the DataSet object and it's Merge function. This could be used to
combine both of these resultsets.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"Tome73" <To****@discuss ions.microsoft. com> wrote in message
news:62******** *************** ***********@mic rosoft.com...
How can I easily add the rows of DataTable1 to the rows of DataTable2.
Both
queries are from the same table. I can always use the column names with
myRow["name"], but I was wishing for a shortcut. When I try this it doesn't
work.

for (int i = 0; i < dataTable1.Rows .Count; i++)
{
myRow = dataTable2.NewR ow();
myRow = dataTable1.Rows[i];
dataTable2.Rows .Add(myRow);
}
return dataTable2;

Jul 21 '05 #2
Ben, it would seem that the merge function is mostly for unlike datasets and
the examples that are given in the SDK only addresses this issue. Furthermore
the examples go from datasets to tables to rows back to tables to rows to
datasets to tables again etc. Very hard to follow for a newbe. I was hoping
for something that took one line of code instead of fifty as with the
examples. lol I guess I will need to write a subroutine to handle it.
Something like
DataTable newDataTable = myMerge(datatab le1, datatable2);

Thanks for the reply.

"Ben Lucas" wrote:
Look at the DataSet object and it's Merge function. This could be used to
combine both of these resultsets.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"Tome73" <To****@discuss ions.microsoft. com> wrote in message
news:62******** *************** ***********@mic rosoft.com...
How can I easily add the rows of DataTable1 to the rows of DataTable2.
Both
queries are from the same table. I can always use the column names with
myRow["name"], but I was wishing for a shortcut. When I try this it doesn't
work.

for (int i = 0; i < dataTable1.Rows .Count; i++)
{
myRow = dataTable2.NewR ow();
myRow = dataTable1.Rows[i];
dataTable2.Rows .Add(myRow);
}
return dataTable2;


Jul 21 '05 #3
Actually, it is really for DataSets that are more similar than different.
It provides capabilities for handling DataSets that do have differences, but
it should be easier to use if your DataSets are not different. In fact, the
docs actually state in the page for "DataSet.Me rge Method (DataTable)", "The
Merge method is used to merge two DataSet objects that have largely similar
schemas."

For example, given dataTable1 and dataTable2 as provided in your original
post:

dataTable1.Tabl eName = "myTable"; //The Data Table names should be the same
so that the merge function can match them up
dataTable2.Tabl eName = "myTable";

DataSet ds = new DataSet();
ds.Tables.Add(d ataTable1);
ds.Merge(dataTa ble2);

At this point, the DataSet will contain one table with the rows from both
tables.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Tome73" <To****@discuss ions.microsoft. com> wrote in message
news:F8******** *************** ***********@mic rosoft.com...
Ben, it would seem that the merge function is mostly for unlike datasets
and
the examples that are given in the SDK only addresses this issue.
Furthermore
the examples go from datasets to tables to rows back to tables to rows to
datasets to tables again etc. Very hard to follow for a newbe. I was
hoping
for something that took one line of code instead of fifty as with the
examples. lol I guess I will need to write a subroutine to handle it.
Something like
DataTable newDataTable = myMerge(datatab le1, datatable2);

Thanks for the reply.

"Ben Lucas" wrote:
Look at the DataSet object and it's Merge function. This could be used
to
combine both of these resultsets.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"Tome73" <To****@discuss ions.microsoft. com> wrote in message
news:62******** *************** ***********@mic rosoft.com...
> How can I easily add the rows of DataTable1 to the rows of DataTable2.
> Both
> queries are from the same table. I can always use the column names with
> myRow["name"], but I was wishing for a shortcut. When I try this it
> doesn't
> work.
>
> for (int i = 0; i < dataTable1.Rows .Count; i++)
> {
> myRow = dataTable2.NewR ow();
> myRow = dataTable1.Rows[i];
> dataTable2.Rows .Add(myRow);
> }
> return dataTable2;
>


Jul 21 '05 #4

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

Similar topics

8
8346
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though the records are sorted by row numbers. (I had to split the fields to different sheets because Excel has a limit of 256 fields in each sheet) My sheets are quite large (~55,000 rows and 200 columns each) and I'll have to repeat this action many...
2
3255
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491 (Internationalized Domain Names / IDNA) which is something that I also need to support. The problem that I've been struggling with in .NET is that of Unicode Code Points > 0xFFFF. These points are encoded into UTF8 using the Surrogate Pair encoding scheme that...
4
1957
by: mike | last post by:
I have a database table like the following: id|name|item_id|sequence and the following instance data: 1|Apple|419841|1 2|Orange|419841|2 3|Banana|935890|1 4|Lime|959081|1
3
338
by: Tome73 | last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both queries are from the same table. I can always use the column names with myRow, but I was wishing for a shortcut. When I try this it doesn’t work. for (int i = 0; i < dataTable1.Rows.Count; i++) { myRow = dataTable2.NewRow(); myRow = dataTable1.Rows; dataTable2.Rows.Add(myRow);
5
1725
by: Matthias Nagl | last post by:
Hello List! I would like to combine the contents of several rows of a subquery. After several hours of search in the documentation and the internet I didn'T find a solution and hope anyone can help. My problem: Let's say I've got a table in the following form: SELECT * FROM test;
2
2542
by: rpeacock | last post by:
I have a function that takes a field with values separated by commas within the field and splits them to multiple rows. Example: Field - Interior Value - abc,def,efg,ghi Output: ID Item 1 abc 2 def
5
2516
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in the database. Not too bad but ugly nonetheless. I succedded in creating the process using multiple stored procedures, but the report takes hours to run in Crystal which more less indicates I failed to get a workable solution. I have a few...
3
2830
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
1
1626
by: dlee360 | last post by:
Hello! So I've been trying to figure out how to do the following in T-SQL: Orig Table: Col1 Col2 Col3 Set A Null Null 20 Set A Null 20 Null Set A 10 Null ...
0
7991
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8395
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8398
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8050
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6719
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5850
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
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
1250
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.