I am working from the Beginning ASP.NET DB book. I copied the code and changed the db path. When I run the code I receive the following error message: Operation must use an updateable query..
My code is:
<%@ Page Language="
VB" Debug="true" %>
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<html>
<head>
<title>Validating a Field</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<table id="Table1"
style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px"
cellSpacing="0" cellPadding="0" width="300" border="0">
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label1" runat="server">CategoryName</asp:Label>
</td>
<td>
<asp:TextBox id="txtCategoryName" runat="server" width="193" />
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label2" runat="server">Description</asp:Label>
</td>
<td>
<asp:TextBox id="txtDescription" runat="server" width="193" />
</td>
</tr>
<tr>
<td style="WIDTH: 115px" colSpan="2">
<asp:Button id="btnInsert" runat="server"
OnClick="btnInsert_Click" width="298" text="INSERT!" />
</td>
</tr>
</table>
<asp:RequiredFieldValidator id="rfvCategoryName" runat="server"
style="Z-INDEX: 102; LEFT: 316px; POSITION: absolute; TOP: 14px"
ErrorMessage="Please insert the new category name"
ControlToValidate="txtCategoryName" />
</form>
</body>
</html>
<script language="
VB" runat="server">
Dim objConnection As OleDbConnection
Sub Page_Load(Source as Object, E as EventArgs)
Dim strDBPath As String
strDBPath = Server.MapPath("..\Database\Northwind.mdb")
objConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OleDb.4.0;DATA Source=" & strDBPath & ";" )
End Sub
Sub btnInsert_Click(Sender As Object, E As EventArgs)
If Page.IsValid Then
Dim strSQL As String = "INSERT INTO Categories " & _
"(CategoryName, Description) VALUES (?, ?)"
Dim dbComm As New OleDbCommand(strSQL, objConnection)
dbComm.Parameters.Add("CategoryName", OleDbType.VarChar, 32, "CategoryName")
dbComm.Parameters.Add("Description", OleDbType.VarChar, 128, "Description")
dbComm.Parameters("CategoryName").Value = txtCategoryName.Text
dbComm.Parameters("Description").Value = txtDescription.Text
Try
objConnection.Open()
dbComm.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
Response.End
Finally
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If
End Try
Response.Write("A new record has been added")
Response.End
End If
End Sub
</script>