Solved

Checking for data in a dataset...

Posted on 2004-09-01
7
360 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

719 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