|
-
May 18th, 2005, 05:30 AM
#1
Thread Starter
Hyperactive Member
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
-
May 18th, 2005, 05:32 AM
#2
Re: ADO Recordset problem
Could you post your code? What database are yiou using?
-
May 18th, 2005, 05:33 AM
#3
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...
-
May 18th, 2005, 05:35 AM
#4
Thread Starter
Hyperactive Member
Re: ADO Recordset problem
 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
-
May 18th, 2005, 05:42 AM
#5
Thread Starter
Hyperactive Member
Re: ADO Recordset problem
 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
-
May 18th, 2005, 06:40 AM
#6
Frenzied Member
Re: ADO Recordset problem
I assume that COMPUTE returns the results as a separate recordset. Have you tried NextRecordset?
Something like this:
VB Code:
Dim rst As Recordset
Set rst = New Recordset
rst.Open ("....")
'do stuff, then get the next recordset
Set rst = rst.NextRecordset
-
May 18th, 2005, 07:02 AM
#7
Thread Starter
Hyperactive Member
Re: ADO Recordset problem
 Originally Posted by PilgrimPete
I assume that COMPUTE returns the results as a separate recordset. Have you tried NextRecordset?
Something like this:
VB Code:
Dim rst As Recordset
Set rst = New Recordset
rst.Open ("....")
'do stuff, then get the next recordset
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
-
May 18th, 2005, 07:52 AM
#8
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...
-
May 18th, 2005, 08:05 AM
#9
Thread Starter
Hyperactive Member
Re: ADO Recordset problem
 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
-
May 18th, 2005, 08:17 AM
#10
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:
Do While rsInquire.State <> 0
lngRecCnt = 0
Do While rsInquire.EOF = False
.
.
.
rsInquire.MoveNext
Loop
Set rsInquire = rsInquire.NextRecordset
Loop
-
May 18th, 2005, 08:30 AM
#11
Thread Starter
Hyperactive Member
Re: ADO Recordset problem
 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:
Do While rsInquire.State <> 0
lngRecCnt = 0
Do While rsInquire.EOF = False
.
.
.
rsInquire.MoveNext
Loop
Set rsInquire = rsInquire.NextRecordset
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
-
May 18th, 2005, 10:32 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|