grwallace
asked on
Detecting an empty dataset
the followin is a section of code from an application
Private Sub Reg_NumTextBox_GotFocus(By Val sender As Object, ByVal e As System.EventArgs) Handles Reg_NumTextBox.GotFocus
Stock_NumberTextBox.Text = UCase(Trim(Stock_NumberTex tBox.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
Private Sub Reg_NumTextBox_GotFocus(By
Stock_NumberTextBox.Text = UCase(Trim(Stock_NumberTex
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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