Sending Data from an ASP Page to a Database

Sending Data from an ASP Page to a Database

How do I send data from a form in an ASP page to a database table in SQL Server 7.0?


  1. Obtain the data from the ASP page’s Forms collection that the form’s ACTION attribute refers to:
    strValue = Request.Form("FormFieldName")

  2. Either build a SQL statement that uses these values to insert data into a table or pass these values as arguments to a stored procedure that will then insert the values into a table. For example, if the above strvalue was to be inserted into a table named MyTable and into a field named MyField, your SQL statement would be:
    Insert into MyTable (MyField) Values ...value of the variable strValue

So, build this SQL statement:

strSQL = "INSERT INTO MyTable (MyField) Values " & _     "('" & strValue & "')"

And then execute the query by using the Execute method of a Connection object:

  1. Declare the connection
  2. Open it giving it a valid connection string
  3. Execute the query:
    objConn.Execute strSQL

There are other ways to update the database also. How you do it depends on the database you are using. You can use stored procedures to do the above so you do not have to build SQL syntax each time. You can use the Command object in conjunction with the Connection object, etc.


Share the Post: