Solved

Detecting an empty dataset

Posted on 2006-07-04
2
234 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 125 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

775 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