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??
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??