473,854 Members | 1,789 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
21 22744
Sam
Cor,
I read your message but :

1. the link u gave me does not work
2. I don't understand this sentence :

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

Could you explain that to me if you don't mind please ?

Thx

Nov 21 '05 #11
Sam,

Again.

You cannot add a reference from a datarow to 2 datatables. (That is what you
do with Add or insertAt)

Therefore is the only thing that you can do.
Create a copy from the original and add that to your new table
Remove the reference from the first and than add it to the new table
Create an extra dataview instead of that extra table.

The copy you have already, the second seems for me out of sense and the
thirth is probably what you need.

dim dv as new dataview(mydata table)

In fact you have now a complete view on your table. If you want only some
rows than you need a rowfilter

dv.rowfilter = "City = 'Amsterdam'"

I hope this helps

Cor
Nov 21 '05 #12
Sam
I'm very very confused. Sorry :(
Are you actually saying I should do that :

1. Create a copy from the original and add that to your new table
dim dtAllFlows as datatable
dtAllFlows = dtFlow.copy

2.Remove the reference from the first and than add it to the new table
???? what does this mean ?

3. Create an extra dataview instead of that extra table.
What for ? :
Dim dvTmp As new DataView
dvTmp.Table = dtFlow

Could you give a very simple example please, as I really don't
understand the above ?
Sorry for bothering :(
Thx

Nov 21 '05 #13
Sam,

I am only saying that you cannot have the same datarow in 2 datatables.

However you only tell that you want this and I only try to explain you why
this is impossible.

Cor
Nov 21 '05 #14
Sam
I understood this. But you've also tried to explain a work around and I
dont understand it !

You said :
Therefore is the only thing that you can do.
Create a copy from the original and add that to your new table
Remove the reference from the first and than add it to the new table
Create an extra dataview instead of that extra table.
Could you give a little example of this (just a few lines of code) as I
can't get it.

Thx a lot

Nov 21 '05 #15
Sam,

In addition, I give you 3 solutions that can solve your problem. However I
don't know your problem except that an original row cannot be added.

Cor
Nov 21 '05 #16
Sam,

Quickly writen in this messages so watch typos or others.

The first
\\\
dim dtnew as datatable = dtOld.Clone
dtnew.rows.Add( dt.newrow)
dtnew.importrow (dtOld.Rows(0))
///
The second
\\\
dim dtnew as datatable = dtOld.Clone
dtnew.rows.Add( dt.newrow)
dim dr as datarow = dtnew.rows(0)
dt.rows.remove( 0)
dtnew.rows.Add( dr)
///
The third
\\\
dim dv = new dataview(dtOld)
'in a dv the show on a datarow is to get (as I showed you before) as a
datarowview
///

I hope this give some ideas

Cor
Nov 21 '05 #17
Sam
Cor,

All of these three methods have an issue.
As I said before, my code is in a loop. I think it's a good idea I give
the algorithm I'm trying to write so one can help me :

for ........
'reset dtFlows
'fill dtFlows with values based on some requests

'add rows of dtFlows to dtAllFlows (I know I can't do that directely)
next

Therefore, doing one of your two methods wouldn't work as I don't want
to do
dim dtnew as datatable = dtOld.Clone in each loop (that would delete
all the existing rows added before)
Your third method :
dim dv = new dataview(dtOld)
OK but I want to put my dv in a datatable then, how ? Actually to be
more precise, I want to add this new datatable (dataview) to a dataset.

Hope I'm clear enough.

Sam

Nov 21 '05 #18
Sam,

You mean that you want to do this

Dim ds as new dataset
ds.tables.add(t ableOld.copy)

Here the same isue, you cannot add a table to two dataset, because every
datatable has a property dataset which can only hold one dataset.

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

I know it is hard, I cannot change it.

Cor
Nov 21 '05 #19
Sam
NOOOOOOOOOOOO !!!!!!! :-) I think we'll never understand each other on
this one, LOL
I don't want to add a table to two datasets. I just want to :

loop
reset datatable
fill datatable with data

fill newdatatable with rows of datatable above (here is the catch and
I must find another way to do it, as you explained with a lot of effort
that it's impossible ;-))

next

Then add newdatatable to a dataset (this is no problem at all)

Hope this is clear ! Again as I'm in a loop I cannot do
dim dtnew as datatable = dtOld.Clone
as you mentionned before otherwise I would loose the data stored in
dtnew that have been added in previous loops.

Sam

Nov 21 '05 #20

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
9903
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
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...
1
10767
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
9526
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
7927
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
7084
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
5952
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
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
3194
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.