473,399 Members | 2,858 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,399 software developers and data experts.

Looping through a Datatable.

I gota scoot here so I gota make it quick :)

I'm doing a conversion from 2 different databases (2 different software
versions)

I have each table stored in a Datatable, and I'm going to append the columns
from V1 that I need to the V2 table.

After creating the tables (works 100%) i run this code:

DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1)

{

foreach(DataColumn col in row)

{

switch(col.Caption)

{.....

I keep getting errors on the first foreach(DataRow row in tblItemV1)

telling me :

foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not contain a
definition for 'GetEnumerator', or it is inaccessible

Any help on this would be sooo sweet.

Thanks!

Nov 16 '05 #1
3 31352
Hi Ryan,
"Ryan Ternier" <rt******@icompasstech.com> schrieb
DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1)
{
It should be
foreach(DataRow row in tblItemV1.Rows)

Your next foreach won't work either:

it should be:

foreach (DataRow row in tblItemV1.Rows)
{
foreach (DataColumn col in tblItemV1.Columns)
{
switch(col.Caption)
{

}
}
}

Cheers

Arne Janning
foreach(DataColumn col in row)

{

switch(col.Caption)

{.....

I keep getting errors on the first foreach(DataRow row in tblItemV1)

telling me :

foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not contain a
definition for 'GetEnumerator', or it is inaccessible

Any help on this would be sooo sweet.

Thanks!

Nov 16 '05 #2
Thanks for the help Arne!
It makes more sense now :)

I usually code all of my stuff in ASP.NET VB, but I am trying this project
in C# for the heck of it.
tblItemV1 = CreateTable("tblItems",strDBV1, tblItemV1);
tblItemV2 = CreateTable("tblItems",strDBV2, tblItemV2);
.....
DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1.Rows)
{
foreach(DataColumn col in tblItemV1.Columns)
{
switch(col.Caption)
{
case "SourceID":
rowV2[col] = row[col];
break;

That's what I'm curently using at the momemt. However, I can't add the
object 'col' to rowV2 because 'col' isn't from that table, but both
tables have the column SourceID. I know I could do this with a for loop,
but there should be a way of doing it this way as well.

Any help or pointers would be great, thanks!!

/RT

"Arne Janning" <sp*****************@msn.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Hi Ryan,
"Ryan Ternier" <rt******@icompasstech.com> schrieb
DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1)
{


It should be
foreach(DataRow row in tblItemV1.Rows)

Your next foreach won't work either:

it should be:

foreach (DataRow row in tblItemV1.Rows)
{
foreach (DataColumn col in tblItemV1.Columns)
{
switch(col.Caption)
{

}
}
}

Cheers

Arne Janning
foreach(DataColumn col in row)

{

switch(col.Caption)

{.....

I keep getting errors on the first foreach(DataRow row in tblItemV1)

telling me :

foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not contain a definition for 'GetEnumerator', or it is inaccessible

Any help on this would be sooo sweet.

Thanks!


Nov 16 '05 #3
Solved this part, just used the column name as a string instead of the col
object.

case "SourceID":
rowV2["SourceID"] = row[col];
break;
Ryan Ternier" <rt******@icompasstech.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... Thanks for the help Arne!
It makes more sense now :)

I usually code all of my stuff in ASP.NET VB, but I am trying this project
in C# for the heck of it.
tblItemV1 = CreateTable("tblItems",strDBV1, tblItemV1);
tblItemV2 = CreateTable("tblItems",strDBV2, tblItemV2);
....
DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1.Rows)
{
foreach(DataColumn col in tblItemV1.Columns)
{
switch(col.Caption)
{
case "SourceID":
rowV2[col] = row[col];
break;

That's what I'm curently using at the momemt. However, I can't add the
object 'col' to rowV2 because 'col' isn't from that table, but both
tables have the column SourceID. I know I could do this with a for loop,
but there should be a way of doing it this way as well.

Any help or pointers would be great, thanks!!

/RT

"Arne Janning" <sp*****************@msn.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Hi Ryan,
"Ryan Ternier" <rt******@icompasstech.com> schrieb
DataRow rowV2 = tblItemV2.NewRow();

foreach(DataRow row in tblItemV1)
{
It should be
foreach(DataRow row in tblItemV1.Rows)

Your next foreach won't work either:

it should be:

foreach (DataRow row in tblItemV1.Rows)
{
foreach (DataColumn col in tblItemV1.Columns)
{
switch(col.Caption)
{

}
}
}

Cheers

Arne Janning
foreach(DataColumn col in row)

{

switch(col.Caption)

{.....

I keep getting errors on the first foreach(DataRow row in tblItemV1)

telling me :

foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not
contain a definition for 'GetEnumerator', or it is inaccessible

Any help on this would be sooo sweet.

Thanks!



Nov 16 '05 #4

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

Similar topics

1
by: Kelvin | last post by:
Hi All, How to get column value from datarow while datatable looping ? Please advised !
4
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
by: Kelvin | last post by:
Hi All, I wrote a program insert new row between rows while the datatable is looping. It display the error message. Exception Details: System.ArgumentException: This row already belongs to this...
1
by: Kelvin | last post by:
Hi All, While the existing datatable is looping, I can insert new row into datatable, but I can't insert it between datarows. All new rows will inserted into buttom row. Please advise!
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
5
by: Stimp | last post by:
This is a question I'm carrying over from a previous one I made today since I've simplified where the problem is... I have a datatable, tblFeatures, which has around 30 columns (one for each...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
8
by: CK | last post by:
Hi All, Good morning. I had a quick question. I have a public Enum. During page load I want to loop thru the Enum and put those as items in an asp:dropdownList. Does anyone have any sample code to...
3
by: praveenraju | last post by:
Hi, I am reading an excel sheet which contains customer_account_numbers and creating a datable using it. Assume the datatable has values 100,200,300. Now i want to update a CustomerStatus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.