473,379 Members | 1,220 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,379 software developers and data experts.

Problem with DataTable and foreach

Hi
i am selecting a table from a db and assign it via DataAdapter to a DataTable.
I now want to do an action for each ro in the DataTable, for what i choose
foreach to accomplish that. My Problem ist now, that the row count shows me
that there are 5 rows in the DataTable, same as in db, but the action is done
only 4 times. The last row in the DataTable seems to be ignored.

Here the place in the code is use:

//Create Data-Table
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM qmgrs", conn );
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);

//Fill Table with QueueManager data
da.Fill(dt);

foreach (DataRow dr in dt.Rows){
try {

Are there any ideas for this problem??

Thanks, Thorsten
Nov 17 '05 #1
1 4984
Thorsten,

what is the rest of the code after your try statement? is there anything in
there failing that's causing the application to skip whatever action your
trying to do and go straight to the catch exception?

"Thorsten moeller" wrote:
Hi
i am selecting a table from a db and assign it via DataAdapter to a DataTable.
I now want to do an action for each ro in the DataTable, for what i choose
foreach to accomplish that. My Problem ist now, that the row count shows me
that there are 5 rows in the DataTable, same as in db, but the action is done
only 4 times. The last row in the DataTable seems to be ignored.

Here the place in the code is use:

//Create Data-Table
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM qmgrs", conn );
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);

//Fill Table with QueueManager data
da.Fill(dt);

foreach (DataRow dr in dt.Rows){
try {

Are there any ideas for this problem??

Thanks, Thorsten

Nov 17 '05 #2

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

Similar topics

8
by: Rodusa | last post by:
I am getting an error on line 133. I am trying to update a datarow using the find method, but it keeps throwing the error below: int ItemKey = dv.Find(Item.inv_mast_uid); DataRow dr; if...
3
by: Ryan Ternier | last post by:
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...
7
by: Joe | last post by:
Not sure what group this question is better suited for so I sent it to both. I have a DataTable which contains 1545 rows. I have a method that returns a DataTable of distinct rows based on one...
2
by: a | last post by:
I get the error that "Argument"1": cannot convert from 'string' to 'System.Data.DataRow' at the foreach loop to add rows to the DataTable...any ideas how to fix this? Paul ...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
6
by: Pete Wittig | last post by:
Hi, I have a DataTable and I want to get a subset of the rows within it. I use the Select method to get my subset and the results are in a DataRow. I want to put those Rows back into a...
0
by: =?ISO-8859-2?B?UmFmYbMgR2llemdhs2E=?= | last post by:
I have: protected void InitControls() { gvProfile.AutoGenerateColumns = false; DataTable dtProfile = new DataTable("KFS"); // dodajemy kolumny foreach(DataGridViewColumn dc in...
2
by: Ronald S. Cook | last post by:
Does anyone know how to convert an object of type IEnumerable to a DataTable? Thanks, Ron
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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
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...

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.