Results 1 to 13 of 13

Thread: no results found

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    no results found

    creating search system, if no results are found ie sql query gives no results, and therefore assign rs to empty string.....

    i assigned the rs as normal to the sql query and then have a if statement, if rs.EOF then return msgbox bUT getting error saying:
    "cannot use empty object or column name..."

    any ideas???

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    Quote Originally Posted by pame1la
    creating search system, if no results are found ie sql query gives no results, and therefore assign rs to empty string.....

    i assigned the rs as normal to the sql query and then have a if statement, if rs.EOF then return msgbox bUT getting error saying:
    "cannot use empty object or column name..."

    any ideas???
    You should at least check the state of the recordset - 1 means you have a recordset...

    Code:
    If rs.State = 1 Then
        ...put you code in here
    end if
    Last edited by szlamany; Mar 17th, 2005 at 11:45 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: no results found

    but it doesnt let me open the rs, comes up with that error!!! i can only check the state if its open rite?!

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    Quote Originally Posted by pame1la
    but it doesnt let me open the rs, comes up with that error!!! i can only check the state if its open rite?!
    Guessing that you got an error on the SQL side then - so no RS at all...

    So check

    Code:
    If rs is Nothing Then
       MsgBox "Got no RS"
    End if

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: no results found

    Private Sub Serach_Click()
    If txtName.Text = "" Then
    MsgBox "Please enter product name", vbOKOnly, "Search Error"
    Else
    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"""
    rs.Open strTemp, gcnSV, adOpenForwardOnly, adLockReadOnly
    If rs.State = 0 Then
    MsgBox "No records match", vbOKOnly, "Search Result"

    or

    Private Sub Serach_Click()
    If txtName.Text = "" Then
    MsgBox "Please enter product name", vbOKOnly, "Search Error"
    Else
    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"""
    If Str = "" Then
    MsgBox "No records match", vbOKOnly, "Search Result"

    WHAT AM I DOIN WRONG?

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    Quote Originally Posted by pame1la
    Private Sub Serach_Click()
    If txtName.Text = "" Then
    MsgBox "Please enter product name", vbOKOnly, "Search Error"
    Else
    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"""
    rs.Open strTemp, gcnSV, adOpenForwardOnly, adLockReadOnly
    If rs.State = 0 Then
    MsgBox "No records match", vbOKOnly, "Search Result"

    or

    Private Sub Serach_Click()
    If txtName.Text = "" Then
    MsgBox "Please enter product name", vbOKOnly, "Search Error"
    Else
    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"""
    If Str = "" Then
    MsgBox "No records match", vbOKOnly, "Search Result"

    WHAT AM I DOIN WRONG?
    What is this mess at the end of the string??

    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"""


    It should simply be:

    Code:
    Str = "SELECT * From Details WHERE ItemName = '" & txtName.Text & "'"

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: no results found

    ooooppppssss

    its still not returning msgbox, doesnt do anything until i press search again it says, operation not allowed while object is open..

    something still wrong
    does If rsTemp.State = 0 Then

    mean empty???

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    If rsTemp is Nothing will check if the object even loaded...

    Do you have code like:

    dim rsTemp as ADODB.Recordset
    set rsTemp=New ADODB.Recordset

    before you try the OPEN?

    Is your connection string clean?

    If you change the select to something that can't fail - like SELECT 'TEST' - does that work?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: no results found

    Quote Originally Posted by pame1la
    ooooppppssss

    its still not returning msgbox, doesnt do anything until i press search again it says, operation not allowed while object is open..

    something still wrong
    does If rsTemp.State = 0 Then

    mean empty???

    .State = 0 means it's closed. 1 means it's open. 1 doesn't mean it returned any records, just that it's open.
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    Quote Originally Posted by demotivater
    .State = 0 means it's closed. 1 means it's open. 1 doesn't mean it returned any records, just that it's open.
    You are correct - I edited my post. 1 means it's open and the RS is there - columns, metadata - whether it has rows if what EOF is all about...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: no results found

    yeah all seems rite : (

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: no results found

    Quote Originally Posted by pame1la
    yeah all seems rite : (
    Does that mean that SELECT 'TEST' also did not work?

    That would lead me to believe that your connection string isn't any good.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: no results found

    its cool i got it

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