Results 1 to 3 of 3

Thread: ADO Recordset problem

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    ADO Recordset problem

    I am having trouble returning data from an Oracle table...

    I can get data with the following:
    Code:
    Option Explicit
    Public adoDWConnection As ADODB.Connection
    Public adoDWRecordset As ADODB.Recordset
    
    Private Sub Command1_Click()
        OpenDWConnection
        MsgBox GetBalance(Me.txtAccount)
    End Sub
    
    Sub OpenDWConnection()
        Dim strConnection As String
        
        Set adoDWConnection = New ADODB.Connection
        
        strConnection = "Provider=MSDASQL.1;Data Source=DATA_WAREHOUSE"
        adoDWConnection.Open strConnection, "MyLoginID", "MyPassword"
        
    End Sub
    Function GetBalance(strAcctNbr As String) As String
    
        Set adoDWRecordset = New ADODB.Recordset
        
        Dim strSQL As String
        
        strSQL = "SELECT acct_status_id from adhoc_view.curr_acct_status where acct_nbr = '" & strAcctNbr & "'"
        adoDWRecordset.Open strSQL, adoDWConnection, adOpenDynamic
            
        GetBalance = adoDWRecordset![acct_status_id]
        
        adoDWRecordset.Close
    End Function
    But I can NOT get data back if I change my SQL to
    Code:
    select acct_nbr, bill_amt from adhoc_view.curr_bill where acct_nbr = '" & strAcctNbr & "'"
    and change the return to
    Code:
    GetBalance = adoDWRecordset![bill_amt]
    What I get is error number 3021: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

    The SQL returns a valid record if I run it thru TOAD, so I know it works.

    Why would this table not return results?

    Thanks!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    1)
    select acct_nbr, bill_amt from adhoc_view.curr_bill where acct_nbr = '" & strAcctNbr & "'"

    I'm assuming that acct_nbr is a number you DON'T need the single quotes (') around the value. If it is a string then its perfectly ok - see (3) below


    2)
    You did no checks to confirm you have a record to return.
    VB Code:
    1. if adoRst.state=adstateopen then
    2.   if Not adoRst.eof then
    3.    GetBalance = adoDWRecordset("acct_status_id")
    4.   end if
    5. [i] adoRst.Close[/i]
    6. End if

    First I check to make sure the recordset is open,
    then I check for records (EOF - End of file = no records if its set on open of a recordset)
    I changed the Bang (!) to a more nicer way of reading code - probably around the same amount of time to process it...
    Also note that I closed the recordset after I've finished with it.

    3)
    So assuming that a recordset is opening, it means that account number doesn't exist

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375
    1) It's a string...(Stupid billing system)
    2) .State = 1
    .eof = true
    .bof = true
    .recordcount = -1
    3) Account was valid, as TOAD gave me a return (As did SQL Plus)

    I tried all your suggestions, but none worked.

    What DID work is this:
    http://www.able-consulting.com/ADO_C...riverForOracle

    That's right, I used the Connections page from your Signature line and now it works!!

    Thanks for the help!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

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