PDA

View Full Version : Need help with ASP to Access data transfers


Puddinpie
11-11-2010, 01:38 PM
Hello,

I'm new to ASP but not programming in general. What I'm trying to accomplish is to have an ASP page where an EU can make some selections and input some text into fields and, upon clicking a submit button, have that input transferred to an access (.Mdb) database's table.
I'm not sure how to go about this though. I don't know if it would be an SQL line or a dump to a different file type and then to Access (.Mdb) or something I don't know about.
If someone has heard of this before and knows of a tutorial or a demo that is out there so I can try to learn it.

Any ideas?

Thank you.

Old Pedant
11-11-2010, 07:52 PM
<form action="storeit.asp" method="post">
<input name="surname"/>
<input name="firstname"/>
<input name="salary"/>
<input type="submit">
</form>


Code for "storeit.asp":

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("/relative/path/to/yourdata.mdb")

SQL = "INSERT INTO tablename ( surname, firstname, salary, whenAdded ) " _
& " VALUES('" & Replace( Request("surname"), "'", "''" ) & "'," _
& "'" & Replace( Request("firstname"), "'", "''" ) & "'," _
& CDBL( Request("salary") & "," _
& "#" & Now() & "# )"
conn.Execute SQL
conn.Close
%>


Alternative version of "storeit.asp":

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("/relative/path/to/yourdata.mdb")

Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "tablename", conn, 3, 3
RS("surname") = Request("surname")
RS("firstname") = Request("firstname")
RS("salary") = Request("salary")
RS("whenAdded") = Now()
RS.Update
RS.Close
Conn.Close
%>

The second version seems simpler, but it's not good to use in high volume systems. I doubt yours will be "high volume", so use it in good health.

http://www.w3schools.com/asp/default.asp
http://www.w3schools.com/ado/default.asp

Old Pedant
11-11-2010, 07:54 PM
Of course, in place of Server.MapPath and a relative path to the DB, you can use an absolute path: "C:\xyz\whatever.mdb"

Caution: You must provide the IIS user ("IUSR_xxxx", where "xxxx" is the name of the computer where this runs) with READ AND WRITE access to both the directory where the MDB file is and the MDB file itself. It is *NOT* enough to give yourself such access: IIS does *NOT* run with your credentials, it runs with its own. If you are not overworried about security, you can simply give "EVERYONE" (that's a reserved special name in Windows) read/write access to the file and folder.