?
Solved

Detecting an empty dataset

Posted on 2006-07-04
2
Medium Priority
?
242 Views
Last Modified: 2010-04-23
the followin is a section of code from an application

  Private Sub Reg_NumTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Reg_NumTextBox.GotFocus
        Stock_NumberTextBox.Text = UCase(Trim(Stock_NumberTextBox.Text))
        WhereString = " WHERE [Stock Number] = '" & Stock_NumberTextBox.Text & "'"
        SqlSelect = New SqlCommand(SqlStr & WhereString, SqlCon1)
        Da1.SelectCommand = SqlSelect
        Da1.Fill(Ds1)
' Would like something like:-
'        if ds1.eof then
'             msgbox("Stock Number" & Stock_NumberTextBox.Text  & " does Not Exist")
'        end if
    End Sub

This works fine, but I would like to be able to detect if the query returns no data - like .EOF in classic ADO.

Is there a simple way of doing this?

thanks
0
Comment
Question by:grwallace
[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
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 375 total points
ID: 17036823
Try:

     If ds1.Tables(0).Rows.Count = 0 Then
         MessageBox.Show("Dataset is empty")
     End If
0
 
LVL 9

Expert Comment

by:checoo
ID: 17036884
The DataAdapter's Fill method also returns the number of rows successfully added to or refreshed in the DataSet. So you can check the return value of the statement Da1.Fill(Ds1) to fidn out if any rows have been added to the dataset
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
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…
Suggested Courses

764 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