The following code updates records in a Microsoft Access database. The Access database is called 'Customers' and has a table called 'tblCustomers'. The database is located in the folder 'H:\Inetpub\wwwroot\code\Customers.mdb'.
The code simply updates all the records where the LastName equals 'Wall' and updates the FirstName to 'John'. A label control 'label1' displays the text 'Record(s) updated.'
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.Oledb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load()
Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & _
"Data Source=H:\Inetpub\wwwroot\code\Customers.mdb")
Connection.Open()
Dim Command As New OleDbCommand("Update tblCustomers Set " & _
"FirstName=@FirstName WHERE LastName=@LastName", Connection)
Command.Parameters.Add(New OleDbParameter("@FirstName", "John"))
Command.Parameters.Add(New OleDbParameter("@LastName", "Wall"))
Command.ExecuteNonQuery()
Connection.Close()
Label1.Text = "Record(s) updated."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id=Head1 runat="server">
<title>Update Customers</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID=Label1 runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Get the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.