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.
[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
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