473,624 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining datatables

Hey there, just starting out using data tables, can anyone tell me how
to combine 2 tables?

Ive tried just coyping the info from 1 table to another, which both
have exactly the same table layout
data is a datatable
data1 is a datatable

data.Rows.Add(d ata1.Rows(0).It em(0))

but it dosnt work, can anyone tall me what im doing wrong?

Jul 19 '06 #1
11 4629
Not sure if I understand completely, but are you asking how you can
copy the CONTENTS of one datatable into another? Or do you want to
MERGE the two tables, creating a new table that has columns from both?
How are both tables constructed previously? Post code if necessary.

Jul 19 '06 #2
Bonzol,

One of the things you have to know when working with datarows and datatables
is that you never can have a datarow in more than one table. Simple because
of the fact that the datarow has a property that references to the table it
is in.

However you can use copies of datarow.

But first answer the question from Steven.

Cor

"Bonzol" <Bo****@hotmail .comschreef in bericht
news:11******** **************@ s13g2000cwa.goo glegroups.com.. .
Hey there, just starting out using data tables, can anyone tell me how
to combine 2 tables?

Ive tried just coyping the info from 1 table to another, which both
have exactly the same table layout
data is a datatable
data1 is a datatable

data.Rows.Add(d ata1.Rows(0).It em(0))

but it dosnt work, can anyone tall me what im doing wrong?

Jul 19 '06 #3
Ahh sorry for not being clear,

I want to copy the contents of one table to another

I have been playing around and have now tried

Dim itemadd As DataRow = data.NewRow()
itemadd = data1.Rows(0).I tem(0)
data.Rows.Add(i temadd)

but does not work.

Jul 19 '06 #4
tables were previously created via
Public Function jWildCard(ByVal table1 As String, ByVal returncolumn
As String, ByVal table2 As String, ByVal checkcolumn As String, ByVal
table1joinField As String, ByVal table2joinField As String, ByVal
checkvalue As String) As DataTable
'
Dim StringToReturn As String

StringToReturn = ""
Dim SQL As String
SQL = "SELECT " + table1 + "." + returncolumn + " FROM " +
table1 + " INNER JOIN " + table2 + " ON " + table1 + "." +
table1joinField + " = " + table2 + "." + table2joinField + " WHERE(" +
table2 + "." + checkcolumn + " LIKE '%" + checkvalue + "%')"
Dim dataAdapter As System.Data.Ole Db.OleDbDataAda pter
dataAdapter = New System.Data.Ole Db.OleDbDataAda pter(SQL,
Me.OleDbConnect ion1)

Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
dataAdapter.Fil l(dt)
Return dt
this is done twice and both tables have the same Select table and
return coloumn.

Jul 19 '06 #5
Ok try this:

Dim newRow as datarow = secondtable.New Row()
newRow.ItemArra y = oldRow.Itemarra y()
secondtable.Row s.add(newRow)

.... where oldRow is a row from your old table.
This code would be inserted in a 'for each' loop to get each row from
the old table.

Good luck.

Jul 19 '06 #6
Bonzol,

Your select is impossible with a Option Strict on.

Therefore it can give unpredictiable results depending on the values that
are in your variables.

Therefore I doubt if it is wise to start with trying to use methods as
merge, importrow etc, if you have not solved this before and know what you
are doing.

Just my thought,

Cor
"Bonzol" <Bo****@hotmail .comschreef in bericht
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
tables were previously created via
Public Function jWildCard(ByVal table1 As String, ByVal returncolumn
As String, ByVal table2 As String, ByVal checkcolumn As String, ByVal
table1joinField As String, ByVal table2joinField As String, ByVal
checkvalue As String) As DataTable
'
Dim StringToReturn As String

StringToReturn = ""
Dim SQL As String
SQL = "SELECT " + table1 + "." + returncolumn + " FROM " +
table1 + " INNER JOIN " + table2 + " ON " + table1 + "." +
table1joinField + " = " + table2 + "." + table2joinField + " WHERE(" +
table2 + "." + checkcolumn + " LIKE '%" + checkvalue + "%')"
Dim dataAdapter As System.Data.Ole Db.OleDbDataAda pter
dataAdapter = New System.Data.Ole Db.OleDbDataAda pter(SQL,
Me.OleDbConnect ion1)

Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
dataAdapter.Fil l(dt)
Return dt
this is done twice and both tables have the same Select table and
return coloumn.

Jul 20 '06 #7
Steven,

If you are using the 2.0 framwork you can to the following:

Dim newTable as New System.Data.Dat aTable = dt.DefaultView. ToTable

Just make sure you don't have any rowfilters set on the default view.

Cheers,
Rob Panosh
Steven Nagy wrote:
Ok try this:

Dim newRow as datarow = secondtable.New Row()
newRow.ItemArra y = oldRow.Itemarra y()
secondtable.Row s.add(newRow)

... where oldRow is a row from your old table.
This code would be inserted in a 'for each' loop to get each row from
the old table.

Good luck.
Jul 20 '06 #8
Sorry mean't to send to Bonzol.

Cheers,
Rob

Rob Panosh wrote:
Steven,

If you are using the 2.0 framwork you can to the following:

Dim newTable as New System.Data.Dat aTable = dt.DefaultView. ToTable

Just make sure you don't have any rowfilters set on the default view.

Cheers,
Rob Panosh
Steven Nagy wrote:
Ok try this:

Dim newRow as datarow = secondtable.New Row()
newRow.ItemArra y = oldRow.Itemarra y()
secondtable.Row s.add(newRow)

... where oldRow is a row from your old table.
This code would be inserted in a 'for each' loop to get each row from
the old table.

Good luck.
Jul 20 '06 #9
Rob,
Dim newTable as New System.Data.Dat aTable = dt.DefaultView. ToTable
Dim newTable as DataTable = dt.copy

does the same without thinking about the rowfilter and version.

http://msdn2.microsoft.com/en-us/lib...able.copy.aspx

I got the idea you did forever miss this one.
(However this cannot be the solution from the problem from the OP)

Cor
Jul 20 '06 #10

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

Similar topics

2
2062
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 schema as my
2
3264
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...
2
4324
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, everything works fine!!
6
1842
by: Red | last post by:
Hi all, I would like to ask how to combine 2 field into one column. For example I have field first name and last name. When I show it to the datagrid I want to show it as one column, for example first name: Jack, lastname: sun become Jack sun. Thanks
4
2254
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 the current code that might be made.
1
1251
by: SMai24 | last post by:
I have two datatables in a dataset, i need to combine both of them into one table. Given that both tables have the same columns. Other than looping, anyone suggestions? Thanx in adavnce!!
2
4120
by: J055 | last post by:
Hi I need to search a number of DataTables within a DataSet (with some relationships) and then display the filtered results in a GridView. The Columns that need to be displayed come from 2 of the tables but the search needs check 3 or 4 tables. Do I need to create a new DataTable which has the columns from both the tables so I can display in the Gridview or can I get the columns somehow from the DataSet without creating a new table? I...
0
1518
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 second datatable contains the detail records and has columns such as Id, BatchId (which links to...
3
2832
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...
0
8231
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
8672
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
8614
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...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7153
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...
0
4075
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
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
2
1474
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.