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

C# : How to Loop through a dataset

62
Hi Need a bit of help please:

How do I write the following VB.NET code in C#?

For count = 0 To ds.Tables("USERS").Rows.Count - 1

UserID = (ds.Tables("USERS").Rows(count)!UserID)
cboUserID.Items.Add(UserID)

Next count

Thanks,

Lóan
Nov 27 '07 #1
7 26969
rrocket
116 100+
It should be:
Expand|Select|Wrap|Line Numbers
  1. for(count=0; ds.Tables("USERS").Rows.Count; count++)
  2. {
  3. UserID = (ds.Tables("USERS").Rows(count)!UserID)
  4. cboUserID.Items.Add(UserID)
  5. }
  6.  
  7.  
Nov 27 '07 #2
Plater
7,872 Expert 4TB
Hi Need a bit of help please:

How do I write the following VB.NET code in C#?

For count = 0 To ds.Tables("USERS").Rows.Count - 1

UserID = (ds.Tables("USERS").Rows(count)!UserID)
cboUserID.Items.Add(UserID)

Next count

Thanks,

Lóan
Expand|Select|Wrap|Line Numbers
  1. for(int count=0; count<ds.Tables["USERS"].Rows.Count;i++)
  2. {
  3. //I'm just guessing on this line, never seen that syntax before
  4.    UserID = ds.Tables["USERS"].Rows[count]["UserID"];
  5.    cboUserID.Items.Add(UserID)
  6. }
  7.  
Why not just just add ds.Tables["USERS"] as the datasource for "cboUserID" ?
Nov 27 '07 #3
LoanB
62
Hey Rrocket

I have the for Loop right now, but the following code comes up with errirs

UserID = (ds.Tables("USERS").Rows(count)!UserID)

It's not allowing me to use thw bang (!) to specify the field heading. Any other ideas?

Thanks,
Nov 27 '07 #4
LoanB
62
Expand|Select|Wrap|Line Numbers
  1. for(int count=0; count<ds.Tables["USERS"].Rows.Count;i++)
  2. {
  3. //I'm just guessing on this line, never seen that syntax before
  4.    UserID = ds.Tables["USERS"].Rows[count]["UserID"];
  5.    cboUserID.Items.Add(UserID)
  6. }
  7.  
Why not just just add ds.Tables["USERS"] as the datasource for "cboUserID" ?
When I specify the Table name it comes up with an error. Am I leacing something out? In VB I am allowed to specify table name, I know, but cannot get it to work in C#.

Cheers,
Nov 27 '07 #5
Plater
7,872 Expert 4TB
Hey Rrocket

I have the for Loop right now, but the following code comes up with errirs

UserID = (ds.Tables("USERS").Rows(count)!UserID)

It's not allowing me to use thw bang (!) to specify the field heading. Any other ideas?

Thanks,
Use my translation .
Nov 27 '07 #6
LoanB
62
Use my translation .
#
//I'm just guessing on this line, never seen that syntax before
#
UserID = ds.Tables["USERS"].Rows[count]["UserID"];

Trying this, but I get the following error:

"Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)"
Nov 27 '07 #7
LoanB
62
Ahh Right the ToString() Function... Then:

UserID = (ds.Tables["USERS"].Rows[count]["UserID"]).ToString();

Works like a charm

Thanks a mil All!
Nov 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: MrMike | last post by:
I have a Public Function which requires 2 parameters. Public Function X (ByVal FirstParam as String, ByVal SecondParam as String) This function displays various options for the 2 parameters(delete,...
4
by: edpdc | last post by:
VB .NET I would like to know how to loop through each row in a data set and get a value from a colum in the data set. My data set has multiple columns. I know I have to use the datarow class but...
2
by: dSchwartz | last post by:
I need help adding a column to a dataset, but its a little bit more complicated then just that. Here's the situation: I have many xml files in one directory, each which represent a newsletter. I...
3
by: Mark | last post by:
Hi - when working with datasets, is it quicker to loop through the dataset, comparing some column values with predetermined values, or should I apply a filter on the dataset to retrieve the values...
1
by: Shapper | last post by:
Hello, I have this loop: For Each row As DataRow In dsContent("pagename").Tables(0).Rows Dim div As HtmlGenericControl = CType(Page.FindControl(row("tag_name").ToString), HtmlGenericControl)...
4
by: CMW | last post by:
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I need to search each record in the dataset to see if any data is missing from the records (i.e., missing first name,...
3
by: Rudy | last post by:
I am writing a program in VB.NET and as I was debugging a problem I noticed my For loop doesn't want to loop! I originally had a upper bound which was an expression and it wasn't working. WHen I...
7
by: Nitromuse | last post by:
What is the proper way to refer to a dataset as the collection in a For Each, Next Statement? I want to loop through a particular column in the dataset, I've tried the following with no sucess. ...
2
by: Philip Wagenaar | last post by:
I have a dataset that I queried from an excel sheet. I want to loop through the rows, then loop through the columns and write them to a file. But I got stuck pretty quickly: So far: For Each...
16
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter. For every record in tblA where colB = 'abc', I want to update the value in colA. In VB6, using ADO I can loop thru the recordset,set the...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.