Results 1 to 5 of 5

Thread: [RESOLVED] [2005] How to know if no rows are returned?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    83

    Question [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:
    1. Private Sub FindNameToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindNameToolStripButton.Click
    2.         Me.Cursor = Cursors.WaitCursor
    3.         Try
    4.             Me.MAILTableAdapter.FillByName(Me.DetailsDataSet.MAIL, Me.NameToolStripTextBox.Text)
    5.  
    6.         Catch ex As Exception
    7.             MessageBox.Show("Error: " & ex.Message)
    8.  
    9.         End Try
    10.         Me.Cursor = Cursors.Default
    11.     End Sub
    Last edited by rim78; Dec 11th, 2006 at 02:36 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim rowCount As Integer = Me.MAILTableAdapter.FillByName(Me.DetailsDataSet.MAIL, Me.NameToolStripTextBox.Text)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: [2005] How to know if no rows are returned?

    VB Code:
    1. If YourDataset.Tables("NameOfTheTable").Rows.Count = 0 Then
    2.      MessageBox.Show("No rows")
    3. End If

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to know if no rows are returned?

    Quote Originally Posted by Shardox
    VB Code:
    1. If YourDataset.Tables("NameOfTheTable").Rows.Count = 0 Then
    2.      MessageBox.Show("No rows")
    3. End If
    What if the DataTable already had some rows in it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    83

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width