Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Checking for data in a dataset...

Posted on 2004-09-01
Medium Priority
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.


If ds.HasRows Then
     lblNoResults.Visible = False
     lblNoResults.Visible = True
End If
Question by:Weller0123
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
LVL 17

Expert Comment

ID: 11955229
If Not IsDBNull(dr("CustomerID")) Then
      Me.txtCustomerID.Text = CStr(dr("CustomerID"))
      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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 17

Expert Comment

ID: 11955294

Author Comment

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

I have to stick with a dataset.

LVL 17

Assisted Solution

AerosSaga earned 1000 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( _
        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
this was empty
********************continue as needed
        TextBox2.Text = tds.Alphabetical_list_of_products(5).CategoryName

        DataGrid1.DataSource = tds

    End Sub

Accepted Solution

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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