PDA

View Full Version : ASP Databse Problem


NEO
05-26-2003, 04:53 PM
Hi, im now started to learn about databases.

Im trying to show the database using asp. Ive used the following code but its not working.

------------------------------------------------------------------------------------
<%
dim oconn
dim oRS
dim strSource

set oConn=server.createobject("ADODB.connection")
set ors=server.createobject("ADODB.recordset")
strsource = "driver={microsoft access driver (*.mdb)}"
strsource = strsource & "; DBQ=c:/autograph.mdb"
oconn.connectionstring = strsource
oconn.open

sqltext = "select namefirst"
sqltext = sqltext & " FROM admin WHERE adminname=2;"
oRS.Open sqltext, oConn

response.Write "<table border-1><tr>"
response.Write ors.GetString(,-1,"</td><td>","</td></tr><td>","&nbsp;")
response.Write "</td></tr></table>"

ors.Close
set ors=nothing
oconn.Close
set oconn=nothing

%>


But i get this error message!


Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
/database.asp, line 15


The database name is called "Autograph.asp" the tabe is called "Admin" and the colum im wanting to display is called "Name"



Whats the problem, because Im learning this out of a book & Its saying Its wrong ??

skriptkiddie
05-26-2003, 10:55 PM
Try changing this line-
oRS.Open sqltext, oConn

to-
oRS.Open sqltext, oConn, 2, 2

Zebulin
05-27-2003, 03:04 AM
sqltext = "select [name] FROM admin WHERE adminname=2"
oRS.Open sqltext, oConn

displays column "name" from table "admin" where column "adminname" equals 2. name is reserved so enclose it in []

ASP-DEV
05-27-2003, 05:15 AM
check in your database to see if the 'namefirst' column is a text field. if so you will need to retype the following line of code with a ' round the number 2: -

sqltext = sqltext & " FROM admin WHERE adminname='2';"