473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Copying Rows to a Datatable

Hi,
am attempting to create a DataTable by copying a table from a data
set, then filter the rows as follows:

DataTable dt = DataSet1.Tables[0].Copy;

DataRow[] dr = dt.Select("myexpression");

dt.Rows.Clear();

dt.Rows.Add(dr);

I have validated that teh number of columns in the datatable matches
the number of items in the DataRow.ItemArray, but it still throws an
exception on the last line that the index of dr is greater than the
number of columns in the datatable.
Thanks in advance,

Jon

Feb 2 '07 #1
1 1571
I think you are a bit confused, at least the code is confused. What you have
in code clones a datatable and filters it to a subset of rows. Then, source
dataset is cleared which also clears the target dataset because the
dt.select statement actually is a shallow copy/reference assignment and not
a true deep copy. Then you turn around and add the empty datarow objects
back into the cleared datatable. I'm certain that this is not what you want
to do. Otherwise, i'm confused.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
"byrd48" <by*****@rocketmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
Hi,
am attempting to create a DataTable by copying a table from a data
set, then filter the rows as follows:

DataTable dt = DataSet1.Tables[0].Copy;

DataRow[] dr = dt.Select("myexpression");

dt.Rows.Clear();

dt.Rows.Add(dr);

I have validated that teh number of columns in the datatable matches
the number of items in the DataRow.ItemArray, but it still throws an
exception on the last line that the index of dr is greater than the
number of columns in the datatable.
Thanks in advance,

Jon

Feb 4 '07 #2

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

Similar topics

1
by: | last post by:
can all rows from one datatable be copied to another easily without actually traversing each row in the datatable? Thanks for your valuable replies.
3
by: VM | last post by:
How can I copy the contents of one datatable to another datatable? I've already the source table so I only need to copy its rows. Thanks.
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
4
by: JPO | last post by:
Hi there, I'm trying to use MSAccess as a "container" to move data around from one MS-SQL server DB to another. This is basically already a design decision that has been made for a lot of...
11
by: Geoff | last post by:
Hi I have a DataTable with thousands of rows. I want a quick way to insert the rows into a table in an Access database with the same structure. I have been using an update command but found it...
6
by: G .Net | last post by:
Hi I'm wondering if anybody can help me with the following problem? I have a table with several rows. I want to create a new table, with exactly the same structure, but has only a subset of...
7
by: Wayne Gibson | last post by:
Hi All, Was wondering if anybody could help. I'm currently trying to copy a record from datatable to another. I have two problems: 1) Transferring the record from one datatable to another. 2)...
0
by: MathewJose | last post by:
Hi, I have a DatagridView in windows form.It has got a column which has some names that are populated from master table in database.Now i need to copy a set of data against these names. I...
1
by: tshad | last post by:
Running on VS.net 2005, I am trying to copy rows from my datatable to another datatable in the same dataset. The schema would be identical. I need to make the table name "forms" as I am...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.