Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to ASP -insert from form

Status
Not open for further replies.

Zirak

MIS
Feb 3, 2003
164
0
0
US
Hi,
I have to build an ASP form that will insert some data to an Access XP db.
I need to things:
1) Online resources for a beginer that wants to set up a connection to an Access db and use ADO and ASP to manipulate data (although I can connect but I still have lots of problems regarding the file path connection)
2) *****How to pass parameters from an HTML Form to a query and insert it into an Access database.

Thanks

 
Look here...
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
This is how you make a connection

DSN-less

<%
Set conn = Server.CreateObject(&quot;ADODB.connection&quot;)
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;yourDB.mdb&quot;)
conn.open strcon
%>

DSN

<%
Set conn = Server.CreateObject(&quot;ADODB.connection&quot;)
conn.open &quot;your DSN&quot;
%>

Working with forms and ASP

page.html
Code:
<form name=&quot;somename&quot; action=&quot;page.asp&quot; method=&quot;post&quot;>
[b]<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;30&quot;>[/b]
[b]<select name=&quot;option&quot;>
        <option value=&quot;0&quot;> Option 1</option>
	<option value=&quot;1&quot;> Option 2</option>
	<option value=&quot;2&quot;> Option 3</option>
	<option value=&quot;3&quot;> Option 4</option>
	<option value=&quot;4&quot;> Option 5</option>
	<option value=&quot;5&quot;> Option 6</option>
	<option value=&quot;6&quot;> Option 7</option>
	<option value=&quot;7&quot;> Option 8</option>
	<option value=&quot;8&quot;> Option 9</option>
          </select>[/b]
[b]<input type=&quot;text&quot; name=&quot;mail&quot; size=&quot;30&quot;><input type=&quot;submit&quot; value=&quot;Enviar&quot; name=&quot;B1&quot;>[/b]      
</form>
Page.asp
Code:
<% 
'Define Variables
Dim conn ' define the connection
Dim strCon ' define the driver and path to your database
Dim strSQL ' define your SQL instruction
Dim option ' define the variable to receive the value from page.html input field
Dim name ' define the variable to receive the value from page.html select field

name = request.form(&quot;name&quot;)
option = request.form(&quot;option&quot;)

'connection
Set conn = Server.CreateObject(&quot;ADODB.connection&quot;)
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;yourDB.mdb&quot;)
conn.open strcon
strSQL = &quot;Insert into «tablename» (Name,Option) values ('&quot;&name&&quot;', &quot;&option&&quot;)&quot;

'note the difference between the two variables, variable &quot;name&quot; is string so it must have the ' in the beggining and in the end ; variable &quot;option&quot; is integer and don't need the ' 

conn.execute(strSQL)
%>
Hope this helps you if there's something that doesn't work on the code i gave you, please teel me, i'd be glad to help you.

Herminio, Portugal



 
Tho you would be better off using Jet 4 for DSN-less connection

Set conn = Server.CreateObject(&quot;ADODB.connection&quot;)

conn.open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & server.mappath(&quot;databasename.mdb&quot;) & &quot;;Jet OLEDB:Database Password=;&quot;
Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
I've heard that OLEDB is a little persnickety with Access DBs (some data loss can occur) - I've read recommendations against OLEDB connections to Access (though I've never used them - I'm on SQL Server...) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
Hmmm, I heard it was far more stable than the old DRIVER={Microsoft Access .... connection. I hope so since I've changed all my connections to this! Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Don't forget to close your connection and set it to nothing
conn.Close
Set conn=Nothing
 
Thanks a lot Herminio,
Your code realy helped me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top