Help updating a table using access

dthomas31uk

New member
Joined
Oct 27, 2005
Messages
4
Programming Experience
Beginner
Hi, Am trying to create updates to an access database that I have created.

I have a database called Newsletter and one table called News.

In the news table are the fields id (autonumber), Firstname (text), Secondname(text) and Email (text).

Anyway have a simple form on a webpage that allows users to enter their info and update it to the database.

Have come accross a problem and don't know why get the error

'Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.'


here is my code that have created

<%@ Import Namespace="System.Data.OleDb" %>

<html>
<head>
<title>Sample Page using VB</title>
<script runat="server" language="VB">
Sub getData(s As Object, e As EventArgs)
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim objRdr As OleDbDataReader



objConn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Inetpub\wwwroot\Test\Database\Newsletter.mdb")
objCmd = New OleDbCommand("INSERT INTO News (UserId, Firstname, Surname, Email) VALUES (@UserId, @Firstname, @Surname, @Email)", objConn)
objCmd.Parameters.Add("@UserId", 5)
objCmd.Parameters.Add("@Firstname", txtFirstname.Text)
objCmd.Parameters.Add("@Surname", txtSurname.Text)
objCmd.Parameters.Add("@Email", txtEmail.Text)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
Response.Redirect("Update.aspx")
End Sub
</script>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtFirstname" CssClass="textbox" Columns="40" Rows="4" runat="server" /><br />
</p>
<p>
<label>
<asp:TextBox id="txtSurname" CssClass="textbox" Columns="40" Rows="4" runat="server" /><br />
</label>
</p>
<p>
<label>
<asp:TextBox id="txtEmail" CssClass="textbox" Columns="40" Rows="4" runat="server" /><br />
</label>
</p>
<p>
<asp:Button id="btnSubmit" OnClick="getData" Text="Get Data" runat="server" />
</p>
</form>
</body>
</html>


Any advice would be mostly appreciated. I have auto number for my UserId field.

Could this be a problem??
 
My first thought at looking at this code is that you do not want to include the UserID field in the insert query because the number will be autoGenerated by Access.
 
Cheers for that Schenz. Have taken out the fields referring to the autonumber, but get the error

Operation must use an updateable query
 
Back
Top