Link to home
Create AccountLog in
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

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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

Avatar of bcarrolluk
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

<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
 
 

 
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
thats brilliant

Cheers
Awesome