Avatar of bcarrolluk
bcarrolluk
 asked on

How do I Run a SQL Query in ASP?

Ok, so far i have this



------

Ok so what  i need is for some way to take the data that the is entered into the text box at the top of the page and then run it in the SQL query, the query just searches for that phonenumber and brings back the number and the operator.

Then once i have that, i need it to write the Phonenumber and the Operator into a table..

Any help is appreciated :)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CPS LCR Customer List</title>
</head>
 
<body>
 
<form id="form1" name="form1" method="post" action="">
  <label>
  <input type="text" name="Text" id="Text" />
  Please Enter the CPS / LCR Number</label>
</form>
<%
 
if len(request.form("Text")) <> "11" then
      response.write("Error - Please Enter an 11 Digit Number") 
      
else
     response.write("")
end if
 
 
set Con = Server.CreateObject("ADODB.Connection")
con.open "File Name=" & Server.MapPath("EbillzSQL.UDL")
 
SQL = "SELECT CustomerIdentifier, Operator From LCRCustList Where CustomerIdentifier = '" & request.form("Text")& "'"

Open in new window

ASPMicrosoft SQL Server

Avatar of undefined
Last Comment
bcarrolluk

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

your code could continue like this:
set rs = conn.execute(sql)
 
response.write "<table>"
response.write "<tr><th>CustomerIdentifier</th><th>Operator</th></tr>"
 
while not rs.eof
  response.write "<tr><td>" & rs.fields("CustomerIdentifier").value & "</td><td>" & rs.fields("Operator").value & "</td></tr>"
  rs.movenext
wend
 
response.write "</table>"
 
rs.close
 
%>

Open in new window

bcarrolluk

ASKER
OK i ran that and i got this error

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/JamesH/LCRCustList.asp, line 32


The Code now looks like this --

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CPS LCR Customer List</title>
</head>
 
<body>
 
<form id="form1" name="form1" method="post" action="">
  <label>
  <input type="text" name="Text" id="Text" />
  Please Enter the CPS / LCR Number</label>
</form>
<%
 
if len(request.form("Text")) <> "11" then
      response.write("Error - Please Enter an 11 Digit Number") 
      
else
     response.write("")
end if
 
 
set Con = Server.CreateObject("ADODB.Connection")
con.open "File Name=" & Server.MapPath("EbillzSQL.UDL")
 
sql = "SELECT CustomerIdentifier, Operator From LCRCustList Where CustomerIdentifier = '" & request.form("Text")& "'"
 
	
	set rs = conn.execute(sql)
 
response.write "<table>"
response.write "<tr><th>CustomerIdentifier</th><th>Operator</th></tr>"
 
while not rs.eof
  response.write "<tr><td>" & rs.fields("CustomerIdentifier").value & "</td><td>" & rs.fields("Operator").value & "</td></tr>"
  rs.movenext
wend
 
response.write "</table>"
 
rs.close
 
%>
 
</body>
</html>

Open in new window

Cedric Obinna A.

<form id="form1" name="form1" method="post" action="thenameofthissamepage.asp">
  <label>
  <input type="text" name="phonebox" id="Text" />
  Please Enter the CPS / LCR Number</label>
</form>
<%
set Con = Server.CreateObject("ADODB.Connection")
con.open "File Name=" & Server.MapPath("EbillzSQL.UDL")
 
if len(request.form("Text")) <> 11 then
      response.write("Error - Please Enter an 11 Digit Number")
     
else
    phbox = Replace(Request.Form("phonebox"),"'","''")
   ' response.write("")
     SQL = "SELECT CustomerIdentifier, Operator From LCRCustList Where  phonenumberfieldname = '" & phbox & "'"
     
     rs.Open SQL,con
end if
 
 

 
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bcarrolluk

ASKER
thats brilliant

Cheers
bcarrolluk

ASKER
Awesome