Note that there are some explanatory texts on larger screens.

plurals
  1. PODELETE statement causing exception in ASP web site
    primarykey
    data
    text
    <p>Not sure why this is not working and looking for any help. I have an ASP web site that I am building. One page is set up as a Master/Detail page where a GridView is used to show the records within a table. A DetailView with the INSERT, UPDATE AND DELETE STATEMENTS is bound to the SELECT button on my GridView. </p> <p>The INSERT and UPDATE statements work without a problem, however the DELETE statement is throwing an Exception.</p> <p>Here is the code for handling the Exception.</p> <pre><code>protected void DetailsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e) { if (e.Exception != null) { lblError.Text = "A database error has occurred.&lt;br /&gt;&lt;br /&gt;" + "Message: " + e.Exception.Message; e.ExceptionHandled = true; } else if (e.AffectedRows == 0) lblError.Text = "Another user may have updated that product." + "&lt;br /&gt;Please try again."; else GridView1.DataBind(); } </code></pre> <p>The Exception thrown is the e.AffectedRows Exception.</p> <p>I am not sure why my table is not accepting the DELETE Statement, any ideas would be appreciated. Here is the code for DetailView</p> <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConflictDetection="CompareAllValues" ConnectionString="&lt;%$ ConnectionStrings:HalloweenConnectionString %&gt;" DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @original_ProductID AND [Name] = @original_Name AND [ShortDescription] = @original_ShortDescription AND [LongDescription] = @original_LongDescription AND [CategoryID] = @original_CategoryID AND (([ImageFile] = @original_ImageFile) OR ([ImageFile] IS NULL AND @original_ImageFile IS NULL)) AND [UnitPrice] = @original_UnitPrice AND [OnHand] = @original_OnHand" InsertCommand="INSERT INTO [Products] ([ProductID], [Name], [ShortDescription], [LongDescription], [CategoryID], [ImageFile], [UnitPrice], [OnHand]) VALUES (@ProductID, @Name, @ShortDescription, @LongDescription, @CategoryID, @ImageFile, @UnitPrice, @OnHand)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [ProductID], [Name], [ShortDescription], [LongDescription], [CategoryID], [ImageFile], [UnitPrice], [OnHand] FROM [Products] WHERE ([ProductID] = @ProductID)" UpdateCommand="UPDATE [Products] SET [Name] = @Name, [ShortDescription] = @ShortDescription, [LongDescription] = @LongDescription, [CategoryID] = @CategoryID, [ImageFile] = @ImageFile, [UnitPrice] = @UnitPrice, [OnHand] = @OnHand WHERE [ProductID] = @original_ProductID AND [Name] = @original_Name AND [ShortDescription] = @original_ShortDescription AND [LongDescription] = @original_LongDescription AND [CategoryID] = @original_CategoryID AND (([ImageFile] = @original_ImageFile) OR ([ImageFile] IS NULL AND @original_ImageFile IS NULL)) AND [UnitPrice] = @original_UnitPrice AND [OnHand] = @original_OnHand"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="GridView1" Name="ProductID" PropertyName="SelectedValue" Type="String" /&gt; &lt;/SelectParameters&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name="original_ProductID" Type="String" /&gt; &lt;asp:Parameter Name="original_Name" Type="String" /&gt; &lt;asp:Parameter Name="original_ShortDescription" Type="String" /&gt; &lt;asp:Parameter Name="original_LongDescription" Type="String" /&gt; &lt;asp:Parameter Name="original_CategoryID" Type="String" /&gt; &lt;asp:Parameter Name="original_ImageFile" Type="String" /&gt; &lt;asp:Parameter Name="original_UnitPrice" Type="Decimal" /&gt; &lt;asp:Parameter Name="original_OnHand" Type="Int32" /&gt; &lt;/DeleteParameters&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name="Name" Type="String" /&gt; &lt;asp:Parameter Name="ShortDescription" Type="String" /&gt; &lt;asp:Parameter Name="LongDescription" Type="String" /&gt; &lt;asp:Parameter Name="CategoryID" Type="String" /&gt; &lt;asp:Parameter Name="ImageFile" Type="String" /&gt; &lt;asp:Parameter Name="UnitPrice" Type="Decimal" /&gt; &lt;asp:Parameter Name="OnHand" Type="Int32" /&gt; &lt;asp:Parameter Name="original_ProductID" Type="String" /&gt; &lt;asp:Parameter Name="original_Name" Type="String" /&gt; &lt;asp:Parameter Name="original_ShortDescription" Type="String" /&gt; &lt;asp:Parameter Name="original_LongDescription" Type="String" /&gt; &lt;asp:Parameter Name="original_CategoryID" Type="String" /&gt; &lt;asp:Parameter Name="original_ImageFile" Type="String" /&gt; &lt;asp:Parameter Name="original_UnitPrice" Type="Decimal" /&gt; &lt;asp:Parameter Name="original_OnHand" Type="Int32" /&gt; &lt;/UpdateParameters&gt; &lt;InsertParameters&gt; &lt;asp:Parameter Name="ProductID" Type="String" /&gt; &lt;asp:Parameter Name="Name" Type="String" /&gt; &lt;asp:Parameter Name="ShortDescription" Type="String" /&gt; &lt;asp:Parameter Name="LongDescription" Type="String" /&gt; &lt;asp:Parameter Name="CategoryID" Type="String" /&gt; &lt;asp:Parameter Name="ImageFile" Type="String" /&gt; &lt;asp:Parameter Name="UnitPrice" Type="Decimal" /&gt; &lt;asp:Parameter Name="OnHand" Type="Int32" /&gt; &lt;/InsertParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload