473,854 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding rows from one datatable to another

Sam
Hi,
The following code :
For Each r As DataRow In dtFlow.Rows
Dim arow As DataRow = dtAllFlows.NewR ow
arow = r
dtAllFlows.Rows .Add(arow)
Next

leads to the error 'This row already belongs to another table '
at the line dtAllFlows.Rows .Add(arow).
I guess I should just do dtAllFlows = dtFlow.copy, but I can't as the
code above is contained in a For loop and at each iteration, I add new
rows (dtFlow changes at each iteration).

How can I solve this problem ?

Regards

Nov 21 '05 #1
21 22743
Sam,

I assume that this is what you want to do

importrow
http://msdn.microsoft.com/library/de...rtrowtopic.asp

I hope this helps,

Cor
Nov 21 '05 #2
Sam
Thanks Cor ;-)

Nov 21 '05 #3
Sam
Actually, I might have spoken too quickly.

For Each r As DataRow In dtFlow.Rows
Dim arow As DataRow = dtAllFlows.NewR ow
arow = r
dtAllFlows.Impo rtRow(arow)
Next

It looked right but in fact when I try to access the data:

dtallflows.Rows (0).Item(0)

gives :

Run-time exception thrown : System.IndexOut OfRangeExceptio n - Cannot
find column 0.

What's going on ?

Nov 21 '05 #4
Sam

When you try to copy a complete table, than you can use table.copy

However this is a sample from me how to sort a datatable, you see than the
use of the import in it.

\\\
Dim dv As New DataView(dt)
dv.Sort = "bla"
Dim dtnew As DataTable = dt.Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow (dvr.Row)
Next
///

I hope this helps,

Cor
Nov 21 '05 #5
Sam
As I said in the first thread, I don't want to do a copy as I add the
rows in a for loop (concatenate if you prefer). therefore I have to use
ImportRow, which leads to the error mentionned in my second thread...
Can you help further ?

Thx

Nov 21 '05 #6
Sam,.

The only thing you can do is copy it, use an extra dataview, remove it from
the first.

However you cannot have a reference in one datarow to two tables.

There is this property in the datarow that should explain that to you if my
text did not.

http://msdn.microsoft.com/library/de...tabletopic.asp

It is a litte bit difficult to set one address to two tables.

I hope this helps,

Cor
Nov 21 '05 #7
Sam
Ok, I do that now :

Dim dvTmp As new DataView
dvTmp.Table = dtFlow
dtFlow = Nothing
For Each r As DataRowView In dvTmp
dtAllFlows.Rows .Add(DirectCast (r, DataRow))
Next

But the Add line doesn't work ( invalid cast ). How can I add a
datarowview to a datatable ??

Thx

Nov 21 '05 #8
Sam
This should be correct I guess...

dtAllFlows.Rows .Add(r.Row)

But I keep getting the error ; the datarow already exists in another
table :(
How come ??

Nov 21 '05 #9
Sam,

Did you read my message?

How you want to do this

myproperty a = adress of datatable wherein it is connected
datarow.a = table1
datarow.a = both table1 and table2

Cor
Nov 21 '05 #10

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

Similar topics

2
3645
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
3
8288
by: Arek | last post by:
I need to have a simple table. User and application will add rows to it. I've used DataGrid but I can't add rows by application. I've got such code: DataRow row = dataTable.NewRow(); row.BeginEdit(); row.ItemArray.SetValue("0", 0); row.ItemArray.SetValue("0", 1); row.ItemArray.SetValue("0", 2); row.ItemArray.SetValue("0", 3); row.EndEdit(); dataRow.ImportRow(row);
1
1871
by: J. Babe | last post by:
I was wondering how to add the first 20 rows from one datatable to another datatable without getting the error: This row already belongs to another table
3
4893
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
1
3303
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
0
2413
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
7
1676
by: EricJ | last post by:
Hi all im a bit confused here, I m trying to add the rows from 1 dataset.tables(0).rows to another ds2.tables(0).rows.add(row) there is probably a better way to do this than going looping true the rows (if you know tell me ;p), but that is how im trying to do this atm. at a certain point i get an error message : This row already belongs to another table. i dont know w i am doing wrong (not that it is nice code but i added it below...
4
8753
by: VMI | last post by:
I'm working on a questionaire, and I'd like to add the questions to a gridview, so that each row (of two "columns" each) has the question in one field, and the editable section (where the user will enter the answer) in the next field. The questions are not stored in a table, and I'm thinking of saving the answers manually (i.e. no datasource). Is this possible? This is a web app using asp.net 2.0. THanks.
6
2360
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters so I can do this: myDataTable.Rows.Add(array()) instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")
0
1971
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; position: absolute; top: 132px" Width="688px" BackColor="White" BorderColor="#CCCCCC"...
0
9752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11041
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
10692
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
9525
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
7083
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5753
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
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
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
3
3193
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.