...

View Full Version : Help



psyc635
01-25-2003, 09:55 PM
I've been trying all day to get this work, im fairly new at asp, and I need some help, im making a page that is going to take data from a access database using an sql query based on user input. Basically, i want this to display the info in a row in my table. Here is what i have, but i dont know how to get it to take the user input, what should i do

<%
Response.Buffer = true
dim cnn,rst
set cnn = Server.CreateObject("ADODB.Connection")
set rst = Server.CreateObject("ADODB.RecordSet")
cnn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=c:\inetpub\wwwroot\data.mdb;"
strType=Request.form("id1")
sqltext = "SELECT * FROM tbl1 WHERE id=& strType &"
set rst = cnn.Execute(sqltext)
Response.Write rst("id")
Response.Write rst("submitted_by")
Response.Write rst("date")
Response.Write rst("department")
Response.Write rst("date_required_go_live")
%>

It works fine without the varible in there, so, please help

psyc635
01-25-2003, 09:58 PM
Oh, if you need an example of what i am trying to do, here is a link:

[url]http://www.aspalliance.com/aspxtreme/ado/structuredquerylanguagebasics.aspx?pageno=0

Its the one with the drop down box

whammy
01-26-2003, 01:03 AM
Depending on the datatype of id, try either:

sqltext = "SELECT * FROM tbl1 WHERE id=" & strType

or

sqltext = "SELECT * FROM tbl1 WHERE id='" & strType & "'"

:D

psyc635
01-26-2003, 03:51 PM
Thanks, but, now i have a new problem, its the same type i believe, I cant get the variable to work, and I dont know why

<%
' Setting variables
Dim con, sql_update, data_source
data_source = "driver={Microsoft Access Driver (*.mdb)};;DBQ=c:\inetpub\wwwroot\data.mdb;"
formid = "Request.Form('prodType')"
sql_update = "update tbl1 set submitted_by = 'Update Records' where id = "& formid &""

' Creating the Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source

' Executing the sql update code
con.Execute sql_update

' Done. Now Close the connection
con.Close
Set con = Nothing
%>


I get the same error message as before

BTW, i was able to resolve my last problem

whammy
01-26-2003, 03:54 PM
Again, your SQL statement looks wrong...

sql_update = "update tbl1 set submitted_by = 'Update Records' where id = " & formid

psyc635
01-26-2003, 04:07 PM
That didnt work, I changed it to what you had and got this error message:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Undefined function 'Request.Form' in expression.

whammy
01-26-2003, 04:08 PM
Try writing out your SQL statements when you get errors, i.e.:

SQL = "SELECT * FROM WHATEVER"
Response.Write(SQL) : Response.End

The reason it isn't working is because of this:

formid = "Request.Form('prodType')"

Request.Form("") shouldn't have quotes around it, you're turning that into a string that equals "Request.Form('prodType')".

that line should be:

formid = Request.Form("prodType")

It looks like you're having a lot of problems with the syntax, writing out your SQL statements when they error will show you what's being generated.

psyc635
01-26-2003, 04:15 PM
Didnt work again, I got this error message this time:

Syntax error (missing operator) in query expression 'id ='.


If i remove all of the variables the script works fine, the form is not inside the asp page, does it need to be? right now it is an external file

psyc635
01-26-2003, 04:19 PM
Nevermind, I got it to work. Thanks for all your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum