This topic is locked

add 2nd query

10/31/2008 12:24:15 PM
ASPRunnerPro General questions
S
sleighbor author

Hi guys,
My asprunner app is up and running great but I have a question. I have an additional SQL query that returns a number and I would like to stick that anywhere on the page. I am not sure how to add a label or textbox to hold the number and also unsure of where to add the SQL query (asp snippet, event,...).
Any help, examples would be greatly appreciated!
Thank you,

Kevin

Sergey Kornilov admin 10/31/2008

I recommend to use "Insert ASP code snippet" button in Visual Editor.
To output a variable use Response.Write "Hello world"

S
sleighbor author 10/31/2008

Hi Sergey,
I found some examples of using the ASP snippet. I have added the code below to create a button. Where would I add the SQL query in this statement?
str = "<input type=button style=button value=""Users Affected"" onclick=""window.location.href='tablename_view.asp?;"">"
response.write str
thank you,

Kevin

S
sleighbor author 10/31/2008

Hi Sergey,
This is what i have for my code but it is not working. Can you tell me what I am doing wrong please?
Sub nt1restore_Snippet1()

dim rs

set rs = server.createobject("ADODB.Recordset")

rs.open "SELECT COUNT(username) FROM nt1restore WHERE (ignore IS NULL)", dbConnection
Response.Write "<script>" & vbcrlf
End Sub ' nt1restore_Snippet1
Kevin

S
sleighbor author 10/31/2008

I just tried the following code and got an ASP error 438.
dim rs

set rs = server.createobject("ADODB.Recordset")

rs.open "SELECT COUNT(username) AS Expr1 FROM nt1restore WHERE (ignore IS NULL)", dbConnection
Response.Write rs.Expr1 & vbcrlf
Kevin

Sergey Kornilov admin 10/31/2008

Kevin,
looks good to me. I assume you have tested SQL query in Enterprise Manager and it works.
What's the exact error message?

S
sleighbor author 10/31/2008

Error number 483

Error Description - Object doesn't support this property or method
the query works perfectly in SQL. I just noticed in the error message the SQL query shows my original SQL query which is select all instead of my asp snippet query which is a subset. does that help?
Thanks,

Kevin

S
sleighbor author 10/31/2008

I moved the snippet to the top of the page and get the same error on load.
Error number 438

Error description Object doesn't support this property or method

SQL query SELECT username, filename, [ignore], ignorereason, filesize, filedate, notes FROM dbo.nt1restore ORDER BY username
That sql select statement in the error is what I use in my list page and not what I am trying to run with the snippet.
Thanks,

Kevin

Sergey Kornilov admin 10/31/2008

Got it. Instead of
Response.Write rs.Expr1 & vbcrlf
use
Response.Write rs("Expr1") & vbcrlf

S
sleighbor author 10/31/2008

That fixed it! Thanks again Sergey!!
Kevin

S
sleighbor author 10/31/2008

Hey Sergey,
We'll I thought we had it. It is returning a value now but it is not right. Here is my code:
dim rs

set rs = server.createobject("ADODB.Recordset")

rs.open "SELECT COUNT(username) AS Expr1 FROM nt1restore WHERE ignore = 1", dbConnection

Response.Write rs("Expr1") & vbcrlf
In sql Expr1 = 75921. When running this code I am getting 40. Any idea?
Thanks,

Kevin

S
sleighbor author 10/31/2008

Got it. Thank you.
Kevin