Solved

Detecting an empty dataset

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now