Solved

Checking for data in a dataset...

Posted on 2004-09-01
7
356 Views
Last Modified: 2012-08-14
I have just switched from using a datareader to a dataset.

I was using this code below to check for results of the reader's data.  I don't see a hasrows method for dataset.  What is the equivalent.

Thanks!

If ds.HasRows Then
     lblNoResults.Visible = False
Else
     lblNoResults.Visible = True
End If
0
Comment
Question by:Weller0123
  • 5
7 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955229
If Not IsDBNull(dr("CustomerID")) Then
      Me.txtCustomerID.Text = CStr(dr("CustomerID"))
   Else
      Me.txtCustomerID.Text = "NULL"
End If

That Checks for null

and now to iterate through just use
While MyDatareader.Read
do record edits here
End While
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955244
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955259
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955294
0
 

Author Comment

by:Weller0123
ID: 11955416
I just want to see if there is any data at all in the dataset.

I have to stick with a dataset.

Thx...
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 250 total points
ID: 11955497
Then You'll have to do some checking for nulls:

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim cn As System.Data.SqlClient.SqlConnection = _
    New System.Data.SqlClient.SqlConnection( _
    "server=C-176012-C\NetSDK;uid=sa;password=;database=Northwind")
        Dim cmd As System.Data.SqlClient.SqlCommand = _
    New System.Data.SqlClient.SqlCommand( _
    "Select * from [Alphabetical list of products]", cn)
        Dim da As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(cmd)

        Dim tds As dsProducts = New dsProducts()
        da.Fill(tds, tds.Tables(0).TableName)******************************************************
        If Not IsDBNull(tds.Alphabetical_list_of_products(5).ProductName) Then
        TextBox1.Text = tds.Alphabetical_list_of_products(5).ProductName
Else
this was empty
********************continue as needed
        TextBox2.Text = tds.Alphabetical_list_of_products(5).CategoryName

        DataGrid1.DataSource = tds
        DataGrid1.DataBind()

    End Sub
0
 
LVL 8

Accepted Solution

by:
shovavnik earned 250 total points
ID: 11955576
If ds.Tables.Count > 0 And ds.Tables(0).Rows.Count > 0 Then
     lblNoResults.Visible = False
Else
     lblNoResults.Visible = True
End If
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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