Link to home
Start Free TrialLog in
Avatar of grwallace
grwallace

asked on

Detecting an empty dataset

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
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of checoo
checoo

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