Results 1 to 12 of 12

Thread: ADO Recordset problem

  1. #1

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    ADO Recordset problem

    Hi,
    I am using the COMPUTE function in my SQL statement... How do I retrieve the value from the recordset set.. ie. RS.Fields("sum") doesnt work

    Can someone help me please?

    Thanks.

    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: ADO Recordset problem

    Could you post your code? What database are yiou using?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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

    Re: ADO Recordset problem

    Either name the column - Select col1,col2,sum(3) "SumCol" From ...

    Then use rs.fields("SumCol")

    Or simply use rs.fields(2) - ordinal position in the recordset will work as well...

    *** 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

  4. #4

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Re: ADO Recordset problem

    Quote Originally Posted by dee-u
    Could you post your code? What database are yiou using?
    Sure thing.

    Code:
    select QuestionNo,test=Count(Answer), Answer from SurveyA where surveyno = 7 and questionno=2 group by Answer,QuestionNo compute sum(count(answer))
    Using SQL Server database with ASP on server side.

    I just dont know how to bring in the "Compute Sum(Count(answer))" value (ABOVE) into my ADO recordset.

    Thanks.
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  5. #5

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Re: ADO Recordset problem

    Quote Originally Posted by szlamany
    Either name the column - Select col1,col2,sum(3) "SumCol" From ...

    Then use rs.fields("SumCol")

    Or simply use rs.fields(2) - ordinal position in the recordset will work as well...

    "Item cannot be found in the collection corresponding to the requested name or ordinal"

    I need to use the COMPUTE function in SQL.
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  6. #6
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: ADO Recordset problem

    I assume that COMPUTE returns the results as a separate recordset. Have you tried NextRecordset?
    Something like this:
    VB Code:
    1. Dim rst As Recordset
    2.     Set rst = New Recordset
    3.     rst.Open ("....")
    4.     'do stuff, then get the next recordset
    5.     Set rst = rst.NextRecordset

  7. #7

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Re: ADO Recordset problem

    Quote Originally Posted by PilgrimPete
    I assume that COMPUTE returns the results as a separate recordset. Have you tried NextRecordset?
    Something like this:
    VB Code:
    1. Dim rst As Recordset
    2.     Set rst = New Recordset
    3.     rst.Open ("....")
    4.     'do stuff, then get the next recordset
    5.     Set rst = rst.NextRecordset
    Thanks for replying,
    however, I get the following error 'Operation is not allowed when the object is closed'

    also I dont think I can change use the nextrecord set as I need records from both record sets in a while loop.

    e.g.

    Code:
    set rs  =  oconn.execute(strSQL,blah,blah)
    set rs2 = rs.nextrecordset
    
    while not eof rs      ' Loop through data on both recordsets.
    
           rs.fields("Answer")
           rs2.fields(0)
    loop
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

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

    Re: ADO Recordset problem

    If you have query analyzer, you should test the query in QA until it's working.

    That will show you how many recordsets you get and what the columns are called and how they are configured...

    *** 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

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Re: ADO Recordset problem

    Quote Originally Posted by szlamany
    If you have query analyzer, you should test the query in QA until it's working.

    That will show you how many recordsets you get and what the columns are called and how they are configured...

    Hi,
    I have tested in QA and it appears to work correctly.. I just cant seem to retreive the COMPUTED field on the Web page.. the QA returns the first set of data at the top of the results page and the Comuted field at the bottom.. does this indicate that it is infact 2 seperate recordsets?

    Craig.
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

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

    Re: ADO Recordset problem

    If there are two sets of headings in the RESULTS PANEL - then they are two recordsets.

    You can further verify this by going to the MESSAGE PANEL - you will have two lines that say "xxx rows affected".

    Something like this will process the separate recordsets...

    VB Code:
    1. Do While rsInquire.State <> 0
    2.    
    3.         lngRecCnt = 0
    4.        
    5.         Do While rsInquire.EOF = False
    6. .
    7. .
    8. .
    9.             rsInquire.MoveNext
    10.         Loop
    11.        
    12.         Set rsInquire = rsInquire.NextRecordset
    13.        
    14.     Loop

    *** 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 cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Re: ADO Recordset problem

    Quote Originally Posted by szlamany
    If there are two sets of headings in the RESULTS PANEL - then they are two recordsets.

    You can further verify this by going to the MESSAGE PANEL - you will have two lines that say "xxx rows affected".

    Something like this will process the separate recordsets...

    VB Code:
    1. Do While rsInquire.State <> 0
    2.    
    3.         lngRecCnt = 0
    4.        
    5.         Do While rsInquire.EOF = False
    6. .
    7. .
    8. .
    9.             rsInquire.MoveNext
    10.         Loop
    11.        
    12.         Set rsInquire = rsInquire.NextRecordset
    13.        
    14.     Loop
    ]

    unfortunately that wont work with my sql table results.

    I am using a test=count of each Answer, ie. how many people said Yes or No.

    My results page looks like this.

    Question: Do you like apples?

    Answer % Responses.
    Yes 50 10
    No 50 10
    Total Responses : 20

    so I use the query :

    'select test=count(Answer) from SurveyA where surveyno = 7 and questionno=2 group by Answer,QuestionNo compute(Answer)'


    basically, I need the value from the Compute answer First for each question, so I can work out the percent of answers selected for each question.
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  12. #12
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ADO Recordset problem

    You cannot access both recordsets at the same time. Once you call NextRecordset, the previous recordset is closed.
    Move the data from the first recordset into an array (see Recordset.GetRows method). Then get the value from the second recordset and finally process through the array.

    Or use With Rollup instead of Computed. You will only get one recordset with the following statement

    Code:
    select CustomerId, test=Count(OrderId) 
    From Orders 
    group by CustomerId With Rollup
    With Rollup creates a total for each group and a grand total. Also check out the Grouping aggregate function.

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