My purpose of this example is to show how to get records from an html form and submit that form to an ASP page. This ASP page will then use SQL to enter the records into the database When I started doing ASP, getting records from an ASP page to a database was my 1st thing I wanted to do. I quickly discovered there was a few ways you could do that. This example uses formatted SQL and the Execute method of the Connection object to take data from a html form and submit to an ASP page that processes the data using SQL.
1st page the Input form- This is just a standard html Input form
<%@ Language = "VBScript"%> <% 'Declare all local variables dim conn dim rs dim strconn dim strsql
strsql = "" 'set connection string to local variable-I use a DSN-less connection strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
'build the sql statement based on the input from the form strSQL = "INSERT INTO tblSqlAdd(FirstName, LastName, FavoriteColor) Values('" & request("FirstName") & "', '" & request("LastName") & "', '" & request("Favoritecolor") & "')"
'Set connection object set conn = server.createobject("adodb.connection") conn.open strconn 'Use the execute method of the connection object the insert the record conn.execute(strSQL) conn.close set conn = nothing %> <html><head> <title>SQL Add record example</title> </head>
<body> <% = "Your record has been added" %> </body> </html>