[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2349
  • Last Modified:

Row count in DataView

I have a DataTable that is being load with rows from a database.

Once loaded I put the DataTable in a DataView and filter the results.

     Dim dv As DataView = dt.DefaultView
     dv.RowFilter = "id <> " & ScheduleID

I want to loop through the results BUT before I do that I want to first check if there are any rows to loop through.  Something like

If dv.Rows.Count > 0 Then
    ' Perform loop
End If.

How do I do this with a DataView?
0
cdemott33
Asked:
cdemott33
  • 2
  • 2
1 Solution
 
Shaun KlineLead Software EngineerCommented:
You can use dataview.Count.

As similar option, if you do not necessarily need to perform logic if no rows are in the view is to use the FOR Each r as datarowview in dataview loop.
0
 
cdemott33Author Commented:
Are you saying that I don't need the DataView.Count check if I use the...

For Each row as DataRowView In DataView
    ' Do stuff
Next

Please advise.
0
 
Shaun KlineLead Software EngineerCommented:
The For Each is a means of looping through a collection of items, be that DataRowViews in a DataView or widgets in an IList. The loop will only occur when there are items in the collection.
0
 
vbighamCommented:
That is right.  You may want to do a null check though?  I'm not sure if the DataTable can ever have a DataView that is null..


Dim dv As DataView = dt.DefaultView

If dv IsNot Nothing Then
    For Each row as DataRowView In dv
        ' Do stuff
    Next
End If

Open in new window

0
 
cdemott33Author Commented:
Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now