Solved

Display value of query result in ASP

Posted on 2008-06-14
2
438 Views
Last Modified: 2009-12-16
Hi Experts,

This seems simple enough but I can't figure it out or find a solution,  all I want to do is execute a sql query
sqlNewClients = "SELECT COUNT(AdvisorID) AS NewAdvisorID FROM TFN_Advisors"
And write the result in my ASP page

I need to replace There Are sqlNewClients  with the correct syntax.  Thanks

Dim objCmd

Set objCmd = Server.Createobject("ADODB.Connection")

strConnectionString = "Driver={SQL SERVER};Server=XXX.XX.XXX.XXX;Database=NAME;Uid=user;Pwd=password"

objCmd.Open strConnectionString

objCmd.Execute sqlNewClients

Set objCmd = Nothing

Response.Write("NewAdvisorID")

%>

<BR>

<font color ="navy" size=5><b><%="There Are sqlNewClients %>

<BR>

Open in new window

0
Comment
Question by:millerfw
2 Comments
 

Author Comment

by:millerfw
ID: 21787100
I forgot to add that if the values is zero I want to return the the home site if the values is >0 i want to return to the previous page.  I am assuming I can just right a function to do this just like in HTML.
0
 
LVL 14

Accepted Solution

by:
_Stilgar_ earned 250 total points
ID: 21788495
See code below
Dim objConn, strSQL, rs, val

Set objConn = Server.Createobject("ADODB.Connection")

strConnectionString = "Driver={SQL SERVER};Server=XXX.XX.XXX.XXX;Database=NAME;Uid=user;Pwd=password"

objConn.Open strConnectionString
 

strSQL = "SELECT COUNT(AdvisorID) AS NewAdvisorID FROM TFN_Advisors"

set rs = Server.CreateObject("ADODB.RecordSet")

rs.Open strSQL, Site_Conn

val = rs(0).value

rs.close

set rs = nothing

objConn.close

set objConn = nothing
 

if CInt(val)>0 then response.redirect "/" else response.redirect "/previouspage.asp"

%>

<BR>

<font color ="navy" size=5><b><%="There Are sqlNewClients %>

<BR>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now