Solved

Checking for data in a dataset...

Posted on 2004-09-01
7
358 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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