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

Loop through a dataset to get values, vb .net

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 I'm not sure how
to do this. I would like to use a for each loop.
Any help would be appreciated.
Nov 16 '05 #1
4 136498
Hi,
Actually, datasets do not contain datarows or columns. Only datatables have
them.

Here is a code snippet that does the looping:

Dim dr As DataRow
Dim ds As Dataset
Dim dt As DataTable
<code to fill the dataset>
dt = ds.Tables(0)
For Each dr In dt.Rows
Console.WriteLine (dr("ColName"))
Next
ds.Dispose()

Hope this helps.

"edpdc" <ed***@yahoo.com> wrote in message
news:61*************************@posting.google.co m...
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 I'm not sure how
to do this. I would like to use a for each loop.
Any help would be appreciated.
Nov 16 '05 #2
If you are going to make a point of asking a question in the csharp
newsgroup, you should expect to get your answer in C#.

DataTable tbl = myDataSet.Tables[0];
for (int i = 0; i < tbl.Rows.Count; i++)
{
DataRow myRow = tbl.Rows[i];
string MyValue = myRow["datafieldname"];
}

This can be written more efficiently... I drew out the data types for
clarity.
--- N

"edpdc" <ed***@yahoo.com> wrote in message
news:61*************************@posting.google.co m...
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 I'm not sure how
to do this. I would like to use a for each loop.
Any help would be appreciated.

Nov 16 '05 #3


Thanks for the reply it helped.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
edpdc wrote:
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 I'm not sure how
to do this. I would like to use a for each loop.
Any help would be appreciated.


Since this is a c# ng, code is in c# :)

DataSet ds = new DataSet();
foreach(DataRow dr in ds.Tables[0].Rows)
{
Console.WriteLine(dr["ColName"].ToString());
}

HTH
JB
Nov 16 '05 #5

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

Similar topics

1
by: TJS | last post by:
Is there a way to do this ??
3
by: hazz | last post by:
The datareader below contains two rows of two columns but in the for loop, the values for only the first row are getting printed twice. How do I get to the values of the second row? Thanks. -hazz...
1
by: Garry Jones | last post by:
I want to simplify the following code. I have 4 variables which are to be read in up to ten times. When read in these are to be written to an SQL database. The value of $ct tells me when to stop...
1
by: JIM.H. | last post by:
Hello, How can I loop table names in a dataset? Thanks,
4
by: martin1 | last post by:
Hi, want to loop DataSet to change row background color based on data retrieved from sql db, the color can be blue, yellow, red or purple. Therefore, Is there any way (vb.net) to change dataset...
1
by: Patricio | last post by:
Hello all I have a form that contains several textbox. I have also a DataSet that contains the Fill function by ID. How can I assign the DataSet values into my TextBox? Thanks a lot.
4
by: SteveT | last post by:
I am wanting to populate several treeviews, one for the <TRs> group and one for the <TGsgroup. Is there a simplier way to populate the Treeview than the one I did below? It seems difficult to...
3
by: shapper | last post by:
Hello, I have a stored procedures as follows: SELECT a.ArticleID, a.Title, a.Content, c.CommentId, c.Title, c.Comment FROM Articles a INNER JOIN Comments c ON a.ArticleID = c.CommentID...
1
by: obrienkev | last post by:
Hi all, How do I use the values of the dataset? I want to compare those values with a textBox. I have the table adapter set up to run a Select query on the dataset. Is it something like...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.