Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET error when calling SqlDataSource.Delete

Posted on 2007-11-29
14
Medium Priority
?
1,379 Views
Last Modified: 2008-03-17
I have a gridview which has a ButtonField which calls the DeleteCommand of the GridView. In the code, several parameters are set up and the call is made (SqlDataSource.Delete), however, I get the following error:

"You have specified that your delete command compares all values on SqlDataSource 'SqlDataSource3', but the dictionary passed in for values is empty.  Pass in a valid dictionary for delete or change your mode to OverwriteChanges."}

Any ideas as to what is wrong and how I can resolve this?

Thanks!
0
Comment
Question by:wppiexperts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
14 Comments
 

Author Comment

by:wppiexperts
ID: 20377518
I think I fixed that issue, by changing ConflictDetection=CompareAllValues to OverwriteChanges, however now the delete command will process but it does not delete any rows, even though all the parameters are assigned the correct values.....now I'm stuck...
0
 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20377645
please post the code.
0
 

Author Comment

by:wppiexperts
ID: 20377693
       If e.CommandName = "DeleteFromCart" Then
            Session("original_cart_id") = cartID
            Session("original_cart_userID") = 144
            Session("original_cart_productID") = cart_prodID
            Session("original_PONum") = Nothing
            Session("original_cart_quantity") = qty
            Try
                SqlDataSource3.Delete()

        <DeleteParameters>
            <asp:Parameter Name="original_cart_id" Type="Int32" />
            <asp:Parameter Name="original_cart_userID" Type="Double" />
            <asp:Parameter Name="original_cart_productID" Type="String" />
            <asp:Parameter Name="original_cart_quantity" Type="Int32" />
            <asp:Parameter Name="original_PONum" Type="String" />
        </DeleteParameters>

DeleteCommand="DELETE FROM cart WHERE cart_id = @original_cart_id AND (cart_userID = @original_cart_userID OR (cart_userID IS NULL and @original_cart_userID IS NULL)) AND (cart_productID = @original_cart_productID OR (cart_productID IS NULL AND @original_cart_productID IS NULL)) AND (cart_quantity = @original_cart_quantity OR (cart_quantity IS NULL AND @original_cart_quantity IS NULL)) AND (PONum = @original_PONum OR (PONum IS NULL AND @original_PONum IS NULL))"
                Label3.Text = CalculateTotal(Session("userid"), 1)
            Catch ex As Exception
                Label3.Text = Err.Description
            End Try

        End If
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20377733
OK since you have already changed ConflictDetection=CompareAllValues to OverwriteChanges, I am guessing you only need to have the cart_id in your deleteCommand since that id is an identifier for the record. try rebuilding the command.
0
 

Author Comment

by:wppiexperts
ID: 20377814
no luck. I changed the deletecommand to:
DeleteCommand="DELETE FROM cart WHERE cart_id = @original_cart_id

the delete command just doesn't get fired off.
Is there a way to see the deletecommand that is being actually used against the database (with the variables inserted)?
0
 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20377841
yeah, you can hook to the events of the sqldatasource events like Deleting, and Deleted.
0
 

Author Comment

by:wppiexperts
ID: 20378152
I tried:
Dim strSQL As String = "DELETE FROM cart WHERE cart_id = " & cartID
SqlDataSource3.DeleteCommand = strSQL

no luck, its still not deleting the record
0
 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20378210
place a break point on that line and check that the value of cartID is actually the correct ID of the record that you intend to delete by comparing to the table in the database.
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20380048
What's the source code for GridView? Where have you called the Command Name?
0
 

Author Comment

by:wppiexperts
ID: 20382228
the code for the gridview is:
    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource3" AutoGenerateColumns="False" DataKeyNames="cart_id,cart_userid" FooterStyle-BackColor="#707070" FooterStyle-ForeColor="#FFFFFF" ShowFooter="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
        <Columns>
            <asp:BoundField DataField="cart_userID" HeaderText="cart_userID" SortExpression="cart_userID" Visible="False" />
            <asp:TemplateField HeaderText="cart_id" InsertVisible="False" SortExpression="cart_id"
                Visible="False">
                <ItemTemplate>
                    <asp:Label ID="cart_id" runat="server" Text='<%# Bind("cart_id") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Stock #" SortExpression="cart_productID">
                <ItemTemplate>
                    <asp:Label ID="cart_productID" runat="server" Text='<%# Bind("cart_productID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Quantity" SortExpression="cart_quantity">
                <EditItemTemplate>
                    <asp:TextBox ID="cart_quantity" runat="server" Text='<%# Bind("cart_quantity") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="cart_quantity" runat="server" Text='<%# Bind("cart_quantity") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Unit Total" SortExpression="subtotal">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("subtotal", "${0:C}") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# FormatCurrency(Get_Amount(Eval("Y1_PRICE"),Eval("cart_quantity"))) %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="Label2" Text='<%# FormatCurrency(Get_Total()) %>' Runat="Server"/>
                </FooterTemplate>
                <FooterStyle BorderWidth="0px" Font-Bold="True" HorizontalAlign="Right" />
            </asp:TemplateField>
            <asp:CommandField ButtonType="Button" ShowEditButton="True" />
            <asp:ButtonField ButtonType="Button" Text="Remove"  CommandName="DeleteFromCart"/>
        </Columns>
        <FooterStyle BackColor="Tan" ForeColor="White" />
        <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
        <HeaderStyle BackColor="Tan" Font-Bold="True" />
        <AlternatingRowStyle BackColor="PaleGoldenrod" />
    </asp:GridView>
The ButtonField calls the "DeleteFromCart" routine which essentially has the following lines:
Dim cartID As String = CType(row.FindControl("cart_id"), Label).Text
Dim strSQL As String = "DELETE FROM cart WHERE cart_id = " & cartID
SqlDataSource3.DeleteCommand = strSQL

when I display the sql command that is issued, it is finding the correct value for the cartID and the command itself seems to execute fine (I don't receive any type of error saying there was a syntax error).
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20387027
You aren't referencing the [Delete] CommandName on the grid. How will it come to know that you want to delete from the grid? Add the command name on the rowdeleting event of the grid so that it will fire when you call for deleting of the row.

PS: I've added the code in CAPS just to differentiate between your code and the modified part.


  <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource3" AutoGenerateColumns="False" DataKeyNames="cart_id,cart_userid" FooterStyle-BackColor="#707070" FooterStyle-ForeColor="#FFFFFF" ShowFooter="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" ONROWDELETING="DeleteFromCart">

Open in new window

0
 
LVL 10

Accepted Solution

by:
digitalZo earned 500 total points
ID: 20387054
No wait! Sorry, I made a  mistake. If you have added the Command Name on the button field, that's correct. But you need to reference the Row_Deleting event handler to the grid.

Something like this:

You may want to go through this: http://www.gridviewguy.com/ArticleDetails.aspx?articleID=138

Hope this helps.
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource3" AutoGenerateColumns="False" DataKeyNames="cart_id,cart_userid" FooterStyle-BackColor="#707070" FooterStyle-ForeColor="#FFFFFF" ShowFooter="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" OnRowDeleting="GridView1_RowDeleting>
 
 
 
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 
{
 
int cartID = (int) GridView1.DataKeys[e.RowIndex].Value;
 
[delete query] 
 
}

Open in new window

0
 
LVL 1

Expert Comment

by:Computer101
ID: 21146872
Forced accept.

Computer101
EE Admin
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question