?
Solved

Detecting an empty dataset

Posted on 2006-07-04
2
Medium Priority
?
245 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
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

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

864 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