Solved

Looping through records in dataview in vb.net

Posted on 2014-03-27
4
1,733 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Firing an ASP.NET event on selection of a JQuery datepicker 4 31
JSON  parse help 7 40
JSON Deserialize issue 6 26
Where does legacy ASP.NET initialize language? 2 26
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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