Click to See Complete Forum and Search --> : Sql Count in ASP question
thebmwz4
04-20-2006, 04:15 AM
Hi, i want to have the number of rows in the Database table. However the system cant display the value. Can someone help me see where is the error?
Thanks.
<%dim NumberofBets
Set objRS = Server.CreateObject("ADODB.Recordset")
countSQL = "Select COUNT(*) AS NumberofBets from InvestDetails"
objRS.ActiveConnection = connectDB
objRS.Open countSQL, connectDB
%>
Total : <%=NumberofBets%>
<Eddie>
04-20-2006, 06:20 AM
<%
dim NumberofBets
Set objRS = Server.CreateObject("ADODB.Recordset")
countSQL = "Select COUNT(*) AS NumberofBets from InvestDetails"
objRS.ActiveConnection = connectDB
objRS.Open countSQL, connectDB
%>
Total : <%=NumberofBets%>
Think about what the code above is doing.
First line is the declaration of a variable called NumberofBets. From here you have opened a database connection and passed a query to it which will return the number of records. Note: What you haven't done is then assign the variable NumberofBets to the return value of the recordset...there is no NumberofBets=objRS.Field("NumberofBets")...so when you output the variable NumberofBets, it has no value.
;)
Terrorke
04-20-2006, 07:11 AM
Completly correct.
You do not assign anything to your variable numberofbets
thebmwz4
04-20-2006, 07:19 AM
Yo! thanks for the enlightenment. issue solved, yeah
The 's ' is missing thou.
NumberofBet=objRS.Fields("NumberofBets")
Thanks :)
thebmwz4
04-20-2006, 07:21 AM
Ok, Eddie, Terrorke, thanks for the help!
Improve my understanding now
cheers
Terrorke
04-21-2006, 02:25 AM
Happy we could help :)