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!

Record Count does not show correct number of records 2

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I wrote a script to count the number of records that each user has, not sure what I am doing wrong, because the script sometimes works and sometimes it does not.
Could it be a cache issue? if so how could I fix it?
here is the code I am using
Code:
Username = Request.Form("txtUsername")	
	'Build connection with database
	set conn = server.CreateObject ("ADODB.Connection")		
	conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("mydb.mdb")
	set rs = server.CreateObject ("ADODB.Recordset")


	rs.Open "SELECT count(*)as intTotal FROM mytable where username='" & Session("Username")& "'" , conn, 1 

Response.Write rs("intTotal")
 
My first thought is that your session times out, so your count is looking for a user name of "" (blank). Try doing this:

Code:
Response.Write Session("Username") &" || "
Response.Write rs("intTotal")
[\code]

The reason i suggest this is I have made this mistake a few times.  You can change the Session expiration time limit if you need to a specific number of minutes:
[code]
Session.Timeout=30
 
mmmmm, in the first line you do:
Username = Request.Form("txtUsername")
but that var is not used in the SQL...


Code:
cUsername = Request.Form("txtUsername") 
if trim(cUsername) = ""  then
 response.redirect "somepage.asp"
 response.end
end if

 'Build connection with database
    set conn = server.CreateObject ("ADODB.Connection")        
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("mydb.mdb")
    set rs = server.CreateObject ("ADODB.Recordset")

rs.Open "SELECT count(*)as intTotal FROM mytable where username='" & cUsername & "'" , conn, 1

Response.Write rs("intTotal")
 
foxbox,
I see what you mean, with your help I was able to accomplish what I was requested.

Thank you!!!!! I appreciate it!!!

The Candy man I also appreciate your suggestion

Thank you!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top