Problem Looping through dataset

I am trying to loop through a dataset to read its data and write it elsewhere but it does not seem that I am moving to the next record in the dataset I am reading from.  here is my code

   For Each dr As DataRow In ds.Tables("search_result").Rows

            Dim drRow As Data.DataRow = dsGrid.Tables(0).NewRow

            drRow("AAA") = ds.Tables("search_result").Rows(0).Item("ZZZ").ToString

        Next dr

ds.Tables("search_result"). is the dataset I am reading from.

Please help.   I must be missing something
Who is Participating?
Robert SchuttConnect With a Mentor Software EngineerCommented:
Change this line
drRow("AAA") = ds.Tables("search_result").Rows(0).Item("ZZZ").ToString

Open in new window

drRow("AAA") = dr.Item("ZZZ").ToString

Open in new window

dr being the loop variable, with your current code you are indeed copying from row 0 every time so in a sense 'not moving forward'.
Mike_StevensAuthor Commented:
Thanks Robert.... I  had a feeling I was missing something like that.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.