ado| Tutorial
Site original content, reproduced please indicate the source Web page teaching network .
We can use the INSERT into command in the SQL statement to add a new record to the database table.
To add a record to the datasheet, we first have to create a table forms use the ASP program to collect data from the form, and then use the program to add the collected data to the database:
The following code can be saved in HTML format
<body>
<form method= "POST" action= "demo_add.asp" >
<table>
<tr>
<td> Customer number:</td>
<td><input name= "CustID" ></td>
</tr><tr>
<td> Company Name:</td>
<td><input name= "Compname" ></td>
</tr><tr>
<td> Contact Person:</td>
<td><input name= "Contname" ></td>
</tr><tr>
<td> Address:</td>
<td><input name= "Address" ></td>
</tr><tr>
<td> City:</td>
<td><input name= "City" ></td>
</tr><tr>
<td> Postal Code:</td>
<td><input name= "Postcode" ></td>
</tr><tr>
<td> National:</td>
<td><input name= "Country" ></td>
</tr>
</table>
<br/>
<br/>
<input type= "Submit" value= "Add" >
<input type= "reset" value= "reset" >
</form>
</body>
Specific processing form program: Save As Demo_add.asp
<body>
<%
Set Conn=server.createobject ("ADODB. Connection ")
Conn. Provider= "Microsoft.Jet.OLEDB.4.0"
Conn. Open "E:/webjx/webjx.mdb"
Sql= "INSERT into Customers (Customerid,companyname,"
Sql=sql & "Contactname,address,city,postalcode,country)"
Sql=sql & "VALUES"
Sql=sql & "(' & Request.Form (" CustID ") &", "
Sql=sql & "' & Request.Form (" Compname ") &", "
Sql=sql & "' & Request.Form (" Contname ") &", "
Sql=sql & "'" & Request.Form ("Address") & "', '
Sql=sql & "'" & Request.Form ("City") & "',"
Sql=sql & "' & Request.Form (" postcode ") &", "
Sql=sql & "' & Request.Form (" Country ") &" ') "
On Error Resume Next
Conn. Execute sql,recaffected
If Err<>0 Then
Response.Write ("No update permissions!")
Else
Response.Write ("
End If
Conn.close
%>
</body>
Important NOTE:
Use the SQL INSERT into command to note that:
If the table contains a primary key then you must make sure that you append the data is not repeated, unique, or you will be wrong.
If the table contains an AutoNumber field, do not append the value of the field when you use the append command.
Sometimes why is there no record in the datasheet after the addition?
In the MS Access database, you can set 0-length text fields, hyperlinks, and Memo fields, and if you set a length of 0, you may have no data.
Note: Not all database 0-length strings, and error prompts when records are appended, it is necessary to check the type and length of database fields when we set up the database.