Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total of a RS field

Status
Not open for further replies.

RobNisbet

Programmer
Jul 10, 2001
22
0
0
GB
Hi People,
I've got this bit of code that shows all my records
on an asp page fine, so now I want to add a total at the bottom. I try to add a field to a variable inside the loop but always get zero for the total for some reason. Is there a better way, there doesnt seem to be a method for this????
Thanks
;-)

<%dim total
total=0
do until OracRS.eof%>
<tr> <td>£<%=oracrs.fields.item(&quot;nbc_premium&quot;)%></td>
</tr>
<%total=total+oracrs.Fields(&quot;nbc_premium&quot;).Value
OracRS.MoveNext
loop
Response.Write(total)%>
 
try this to see each time the value of total
and use the fields value like written in the example

do until OracRS.eof%>
<tr> <td>£<%=oracrs(&quot;nbc_premium&quot;)%> </td></tr>
<%total=total+oracrs(&quot;nbc_premium&quot;)
response.write &quot;<tr><td>&quot; & total & &quot;</td></tr>&quot;
OracRS.MoveNext
loop

It should work. If it's working delete the line
response.write &quot;<tr><td>&quot; & total & &quot;</td></tr>&quot;

Regards,
Durug
 
Thanks Durug, but tried that and no change. Total was null and didnt show up on screen. Put total=0 at the top and I got a line of zero's.
If you replace the line total=total+oracrs(&quot;xxx&quot;) with total=total+1 no problems.

The nbc_premium is a number(10,2) in the DB, so should be OK, maybe the value in the RS need type casting into something??, I dunno.

Is there was a ORacRs(&quot;nbc_premium&quot;).total or .sum equivalent that would sort it but I can't find one... does anyone know of a similar method/property??

Thanks
Rob
 
Try Cint(oracrs(&quot;nbc_premium&quot;))
There is no oracrs(&quot;nbc_premium&quot;).total or oracrs(&quot;nbc_premium&quot;).sum in ADO as far as I know. If still dosn't work try to retrieve the value of total from a stroed procedure
 
Thats the badger cheers for that.
total=total+Cint(oracrs(&quot;nbc_premium&quot;)) worked.
Strange tho - how come it needs casting into an int
when the field type should be int already?
is there a property to show what type an RS field is?

Thanks, nice work for a Friday afternoon.......

R
 
Is ASP all variables are of Variant type. Sometimes
CInt, CStr, Cdate is very useful :)
The only way to test the is
if Cint(ala) then
is integer
else
not integer
end if
 
Would adding value to the end of your field statement make a difference (out of curiosity only and the quest to learn what I can) - oracrs.fields.item(&quot;nbc_premium&quot;).value - or is that always implied?

What I find useful is to create a variable for the value of the field and then use that, not the field value to add my totals, that way the variable is already &quot;scoped&quot; - ish ready for adding. I tend to do this at the top of each loop:

Code:
<%dim total
dim newval
total=0
do until OracRS.eof
   newval = oracrs.fields.item(&quot;nbc_premium&quot;).value %>
 <tr> <td>£<%=newval%></td>
 </tr>                      
 <%total=total+newval
 OracRS.MoveNext
loop
Response.Write(total)%>

Derren
[Mediocre talent - spread really thin]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top