Results 1 to 7 of 7

Thread: Another select statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Another select statement

    Hi gurus

    I have the following selct statement

    stringconnec= "select las_name from Table where condition"

    How do I go and check if the select statement came back with a result or not

    Thanks a bunch

  2. #2
    Frenzied Member
    Join Date
    Apr 2003
    Location
    The Future - Skynet
    Posts
    1,157

    Re: Another select statement

    rs.recordcount is one way. This depends on which cursor you use too. I believe you use a snapshot cursor will give the recordcount.

    the other is:

    strSQL="SELECT COUNT(*) FROM TableA
    WHERE BlaBla = 11111"

    msgbox rs.Field(0).value
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: Another select statement

    L.

    Thanks for the replay, but I have a question

    how count(*) will help check if a result came back.

    I am looking for a particular record last_name (smith) within the table if there is a smith the select statement will bring the record but if not the select statement will nothing is here where I need to check if something came back or not

    it seems like count(*) will tell me if there are records on a table. am I missing something

    Thanks for battling

  4. #4
    Frenzied Member
    Join Date
    Apr 2003
    Location
    The Future - Skynet
    Posts
    1,157

    Re: Another select statement

    so do it like this:

    strSQL="SELECT * FROM TableA
    WHERE LastName='Smith'"

    run that throught the recordset with the cursor set to static.

    once it is open, do a recordset.recordcount and that will give you the count.

    Pretty much similar to what I described in the previous post.
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Another select statement

    If using ADO and VB6 test for recordset EOF and BOF if they are true then No records.

    If using ADO.Net and VB.Net for Datareaders check the .HasRows property. For DataSets test if the dataset.Table(#).Rows.RowCount() > 0
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: Another select statement

    Gary/L

    Thanks a bunch, here I am on my first application using .net and having this kind of problems, so thanks for battling with me here

    I was trying to get the same prop or meth from datatable.

    I am using sqlclient to connect to the sql server


    so I have a sqladapter.fill(ds) where ds is my datatable object
    then I populate my datagrid with my ds

    But before I do all this I would like to know if the select statement comes back with something or not

    Thanks again

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Another select statement

    I would look at

    vb.net Code:
    1. DataGridView1.DataSource = ds.Tables(0)
    2.  
    3. If ds.Tables(0).Row.Count() = 0 Then
    4.      'Do Something Else
    5.      MessageBox.Show("No Records Found!","No Data")
    6. End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

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