Solved

Checking for data in a dataset...

Posted on 2004-09-01
7
359 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
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955244
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11955259
0
Independent Software Vendors: 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

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.

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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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