Novice Learn ADO Instance tutorial ADO Add new Record

Source: Internet
Author: User
Tags contains insert sql reset access database
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.