[RESOLVED] [2005] How to know if no rows are returned?
I have a Find button on my form that binds to a dataset. How do check when there is no rows returned and inform the user?
Thanks.
VB Code:
Private Sub FindNameToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindNameToolStripButton.Click
Me.Cursor = Cursors.WaitCursor
Try
Me.MAILTableAdapter.FillByName(Me.DetailsDataSet.MAIL, Me.NameToolStripTextBox.Text)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
Me.Cursor = Cursors.Default
End Sub
Re: [2005] How to know if no rows are returned?
Fill and the like are functions and they return the number of rows retrieved, which Intellisense would have told you.
VB Code:
Dim rowCount As Integer = Me.MAILTableAdapter.FillByName(Me.DetailsDataSet.MAIL, Me.NameToolStripTextBox.Text)
Re: [2005] How to know if no rows are returned?
VB Code:
If YourDataset.Tables("NameOfTheTable").Rows.Count = 0 Then
MessageBox.Show("No rows")
End If
Re: [2005] How to know if no rows are returned?
Quote:
Originally Posted by Shardox
VB Code:
If YourDataset.Tables("NameOfTheTable").Rows.Count = 0 Then
MessageBox.Show("No rows")
End If
What if the DataTable already had some rows in it?
Re: [2005] How to know if no rows are returned?
Thank you for the fast reply! I used what jmcilhinney suggested, dim rowCount to check no. of rows retrieved.