Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all Big Grin :-D

I'm using VB 2008 and VB.NET

I have a database data. Each column namely as name, age and hobby. For 1 person have more than one hobby. Each time user key in the name, it will directly display their age and hobby. So, I need to loop through each item in the dataset.table.row and wondering how to do this.


VB
Dim ds As DataSet
Dim row As DataRow
 
If ds.Tables.Count > 0 Then
   If ds.Tables(0).Rows.Count > 0 Then
      For Each row In ds.Tables(0).Rows
 
Next 
 
???




Can someone help me to teach me to make this loop or give some suggestion to write this loop? Thank you in advance Smile :)
Posted

1 solution

You almost got it. Try
VB
Dim row As DataRow

If ds.Tables.Count > 0 Then
   If ds.Tables(0).Rows.Count > 0 Then
      For Each row In ds.Tables(0).Rows
         var age = row("Age")
         var hobby = row("Hobby")
      Next
 
Share this answer
 
v3
Comments
apple blue 6-Apr-15 4:00am    
Its that the same way should i use if I have my user interface like : http://oi61.tinypic.com/mwy5b8.jpg

And database : http://oi60.tinypic.com/sgmrs3.jpg

Each time user key in the name of name textbox, it also will directly display age and their hobby. I had problem on how to make the loop for hooby column and to display it according to the label. In other word, I would like to make my program display as below :

Name : Jason

Age : 20

Hobby : Swimming
Games
Richard Deeming 7-Apr-15 7:43am    
var age = row("Age")

Can you use var in VB.NET now? I always thought it was a C# feature.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900