Solved

Looping through records in dataview in vb.net

Posted on 2014-03-27
4
1,624 Views
Last Modified: 2014-03-27
Hi!

How do I write the loop so I dont manually have to do like this to achieve my result:( There can be 10 rows or 5 rows). I guess it must be something like:



  Dim id As String
        id = CType(sdsView.Table.Rows(0).ItemArray(5), String)
        id = id + CType(sdsView.Table.Rows(1).ItemArray(5), String)
        Label1.Text = id

Open in new window


For Each rowView As DataRowView in sdsView
    Dim row As DataRow = rowView.Row
    ' Do something '
Next

but I cant figure out exactly how



More code-example

Partial Class _13_mobileservice_mobileservice_group
    Inherits System.Web.UI.Page
    Private sdsView As DataView
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        sdsView = (CType(SqlDataSource3.Select(DataSourceSelectArguments.Empty), DataView))
        Dim id As String
        id = CType(sdsView.Table.Rows(0).ItemArray(5), String)
        id = id + CType(sdsView.Table.Rows(1).ItemArray(5), String)
        Label1.Text = id
    End Sub

Open in new window

0
Comment
Question by:marcgu
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 300 total points
ID: 39958306
Dim dv As New DataView(New DataTable())
Dim id As String = String.Empty
For Each item As DataRow In dv.Table.Rows
      id = id & Convert.ToString(item.ItemArray)
Next
Label1.Text = id
0
 

Author Comment

by:marcgu
ID: 39958535
Hi!

Thanks for fast reply, but the problem is that it now only writs:

System.Object[] (for each record)     instead of the value(s) in the cell.

I probably made a misstake when I tried to use your code in my example.

I changed to this:

Partial Class _13_mobileservice_mobileservice_group
    Inherits System.Web.UI.Page
    'Private sdsView As DataView

   
 Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim dv As New DataView(New DataTable())
        dv = (CType(SqlDataSource3.Select(DataSourceSelectArguments.Empty), DataView))
        Dim id As String = String.Empty
        'id = CType(sdsView.Table.Rows(0).ItemArray(5), String)
        'id = id + CType(sdsView.Table.Rows(1).ItemArray(5), String)
        'Label1.Text = id



        'Dim id As String 
        For Each item As DataRow In dv.Table.Rows
            id = id & Convert.ToString(item.ItemArray)
        Next
        Label1.Text = id




    End Sub

Open in new window

0
 
LVL 5

Assisted Solution

by:jayakrishnabh
jayakrishnabh earned 300 total points
ID: 39958612
replace item.ItemArray with item.ItemArray[5]
0
 

Author Closing Comment

by:marcgu
ID: 39958633
Thanks for quick and professional response. Now it works as I planned.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now