Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT not updatable query

Status
Not open for further replies.

CoolMama

Programmer
Jan 19, 2006
50
US
I am creating my first "insert into database" form. I have a table with textboxes for a new policy to be added to a database. When I hit the add button, I get the error below. Why is this not an updateable query? I'm sure there's some bit of code missing. Also not sure if I set up the Primary Key INSERT correctly.

Code:
<script runat="server">

OleDbConnection dbConn = new OleDbConnection(ConfigurationSettings.AppSettings["policiesDNS"]);
OleDbCommand objCmd;
    
void Page_Load() {}
    
void AddPolicy(Object s, EventArgs e)  {
objCmd = new OleDbCommand("INSERT INTO PFFPolicies(PolicyID, Manual, PageNumber, Title, Notes, Link, LastUpdated) VALUES (@PolicyID, @Manual, @PageNumber, @Title, @Notes, @Link, @LastUpdated)", dbConn);
    
objCmd.Parameters.Add("@PolicyID", 5);
objCmd.Parameters.Add("@Manual", txtManualNo.Text);
objCmd.Parameters.Add("@PageNumber", txtPageNo.Text);
objCmd.Parameters.Add("@Title", txtTitle.Text);
objCmd.Parameters.Add("@Notes", txtNotes.Text);
objCmd.Parameters.Add("@Link", txtURL.Text);
objCmd.Parameters.Add("@LastUpdated", txtLastUpdated.Text);
    
dbConn.Open();
objCmd.ExecuteNonQuery();
dbConn.Close();
Response.Redirect("PFFpolicies_add.aspx");
    }

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<table style="WIDTH: 600px; HEIGHT: 290px" cellspacing="0" cellpadding="6" width="600" align="left">
<tbody>
<tr><td valign="center" align="right">Manual No.</td>
<td valign="center" align="left"><asp:TextBox id="txtManualNo" runat="server" Width="33px" ReadOnly="True">96</asp:TextBox></td></tr>
<tr><td valign="center" align="right">Page No.</td>
<td valign="center" align="left">
<asp:TextBox id="txtPageNo" runat="server"></asp:TextBox>
</td></tr><tr>
<td valign="center" align="right">Policy Title</td>
<td valign="center" align="left"><asp:TextBox id="txtTitle" runat="server" Width="390px"></asp:TextBox></td></tr><tr>
<td valign="center" align="right">URL</td>
<td valign="center" align="left"><asp:TextBox id="txtURL" runat="server" Width="421px"></asp:TextBox></td></tr>
<tr><td valign="center" align="right">Date Last Updated</td>
<td valign="center" align="left"><asp:TextBox id="txtLastUpdated" runat="server"></asp:TextBox></td></tr>
<tr><td valign="center" align="right">Notes</td>
<td valign="center" align="left"><asp:TextBox id="txtNotes" runat="server" Width="437px"></asp:TextBox></td></tr>
<tr><td valign="center" align="left" colspan="2">
<table><tbody><tr><td><asp:Button id="btnAdd" onclick="AddPolicy" runat="server" Text="Add Policy to Database"></asp:Button></td></tr></tbody></table>


[blue]Server Error in '/' Application.
--------------------------------------------------------------------------------

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.

Source Error:


Line 23:
Line 24: dbConn.Open();[/blue]
[red]Line 25: objCmd.ExecuteNonQuery();[/red]
[blue]Line 26: dbConn.Close();
Line 27: Response.Redirect("PFFpolicies_add.aspx");


Source File: D:\web\RISB_SITE\AdminPages\PFFpolicies_add.aspx Line: 25

Stack Trace:


[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
ASP.PFFpolicies_add_aspx.AddPolicy(Object s, EventArgs e) in D:\web\RISB_SITE\AdminPages\PFFpolicies_add.aspx:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292[/blue]

Dawn
 
Are you using MS Access? If so, it's probably a permissions problem. Make sure the ASPNET account has access to the directory and file.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
This database is already being use by other aspx pages I created to read from it. Now I'm just creating the admin pages to update it. So I know the connection is OK. Are you saying there are different permissions to be aware of for updating as opposed to just reading from a database?

Dawn
 
OK, the IS guy changed the permissions and it works now. Thank you!

Actually I found a note in my book which said the exact same thing you did. Perhaps I should pay closer attention to those. :)

Dawn
 
9 out of 10 times if an error in writing to an Access mdb is "query not updateable" it's a permission's issue (the SQL is ok at this point).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top