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

  • Question

  • User285990374 posted

    hi.

    am getting the following error .... i have a grid view with a command field ADD(i e INSERT)..... EDIT and DELETE.....


    edit button works fine but when i click on DELETE its throwing the following error

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

    so can any one help me in this regard...


    Friday, September 3, 2010 8:14 AM

Answers

All replies

  • User1716267170 posted

    Please show us some source code so that we can understand the question better. Thanks.

    Tuesday, September 7, 2010 1:06 AM
  • User285990374 posted

    Source Code:


    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:idakshConnectionString3 %>" 
            DeleteCommand="DELETE FROM [Acsry_Category] WHERE [catId] = @original_catId AND [acsName] = @original_acsName AND [imgUrl] = @original_imgUrl" 
            InsertCommand="INSERT INTO [Acsry_Category] ([catId], [acsName], [imgUrl]) VALUES (@catId, @acsName, @imgUrl)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [Acsry_Category]" 
            
            
            UpdateCommand="UPDATE [Acsry_Category] SET [acsName] = @acsName, [imgUrl] = @imgUrl WHERE [catId] = @original_catId AND [acsName] = @original_acsName AND [imgUrl] = @original_imgUrl" 
            ConflictDetection="CompareAllValues">
            <DeleteParameters>
                <asp:Parameter Name="original_catId" Type="Int32"  />
                <asp:Parameter Name="original_acsName" Type="String" />
                <asp:Parameter Name="original_imgUrl" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="acsName" Type="String" />
                <asp:Parameter Name="imgUrl" Type="String" />
                <asp:Parameter Name="original_catId" Type="Int32" />
                <asp:Parameter Name="original_acsName" Type="String" />
                <asp:Parameter Name="original_imgUrl" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="catId" Type="Int32" />
                <asp:Parameter Name="acsName" Type="String" />
                <asp:Parameter Name="imgUrl" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                  DataKeyNames="catId"
                  DataSourceID="SqlDataSource1" 
                  ShowFooter="True" Height="168px" Width="648px" >
                           
                  <Columns>
                          
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                   <%-- <asp:Label ID="lblID" runat="server" 
                                                          Text='<%#Eval("catId") %>'>
                                    </asp:Label>--%>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Button ID="ButtonInsert" runat="server" 
                                            Text="Insert" CommandName="Add" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            
                            
                             <asp:TemplateField HeaderText="ID" 
                                        SortExpression="Cat ID">
                                <ItemTemplate>
                                    <asp:Label ID="lblcatId" runat="server" 
                                               Text='<%#Eval("catId") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextCatId" runat="server" 
                                                 Text='<%#Bind("catId") %>'>
                                    </asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="TextCatId" runat="server">
                                    </asp:TextBox>
                                </FooterTemplate>
                         </asp:TemplateField> 
                            
                           <asp:TemplateField HeaderText="Accessory Name" 
                                        SortExpression="Accessory Name">
                                <ItemTemplate>
                                    <asp:Label ID="lblAcsryName" runat="server" 
                                               Text='<%#Eval("acsName") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextAcsryName" runat="server" 
                                                 Text='<%#Bind("acsName") %>'>
                                    </asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="TextAcsryName" runat="server">
                                    </asp:TextBox>
                                </FooterTemplate>
                         </asp:TemplateField> 
                         
                         <asp:TemplateField HeaderText="ImageUrl" 
                           SortExpression="ImageUrl">
                                <ItemTemplate>
                                <asp:Label ID="lblImageUrl" runat="server" 
                                           Text='<%#Eval("imgUrl") %>'>
                                </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                <asp:TextBox ID="TextImageUrl" runat="server" 
                                             Text='<%#Bind("imgUrl") %>'>
                                </asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                <asp:TextBox ID="TextImageUrl" runat="server">
                                </asp:TextBox>
                                </FooterTemplate>
                        </asp:TemplateField>                      
                        <asp:CommandField  ShowEditButton="True" />
                          
                        <asp:CommandField ShowDeleteButton="True" />
                  </Columns>
           </asp:GridView> 
        


    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

            ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" 

            DeleteCommand="DELETE FROM [Acs_Category] WHERE [catId] = @original_catId AND [acsName] = @original_acsName AND [imgUrl] = @original_imgUrl" 

            InsertCommand="INSERT INTO [Acs_Category] ([catId], [acsName], [imgUrl]) VALUES (@catId, @acsName, @imgUrl)" 

            OldValuesParameterFormatString="original_{0}" 

            SelectCommand="SELECT * FROM [Acs_Category]" 

            

            

            UpdateCommand="UPDATE [Acs_Category] SET [acsName] = @acsName, [imgUrl] = @imgUrl WHERE [catId] = @original_catId AND [acsName] = @original_acsName AND [imgUrl] = @original_imgUrl" 

            ConflictDetection="CompareAllValues">

            <DeleteParameters>

                <asp:Parameter Name="original_catId" Type="Int32"  />

                <asp:Parameter Name="original_acsName" Type="String" />

                <asp:Parameter Name="original_imgUrl" Type="String" />

            </DeleteParameters>

            <UpdateParameters>

                <asp:Parameter Name="acsName" Type="String" />

                <asp:Parameter Name="imgUrl" Type="String" />

                <asp:Parameter Name="original_catId" Type="Int32" />

                <asp:Parameter Name="original_acsName" Type="String" />

                <asp:Parameter Name="original_imgUrl" Type="String" />

            </UpdateParameters>

            <InsertParameters>

                <asp:Parameter Name="catId" Type="Int32" />

                <asp:Parameter Name="acsName" Type="String" />

                <asp:Parameter Name="imgUrl" Type="String" />

            </InsertParameters>

        </asp:SqlDataSource>

        

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

                  DataKeyNames="catId"

                  DataSourceID="SqlDataSource1" 

                  ShowFooter="True" Height="168px" Width="648px" >

                           

                  <Columns>

                          

                            <asp:TemplateField HeaderText="">

                                <ItemTemplate>

                                   <%-- <asp:Label ID="lblID" runat="server" 

                                                          Text='<%#Eval("catId") %>'>

                                    </asp:Label>--%>

                                </ItemTemplate>

                                <FooterTemplate>

                                    <asp:Button ID="ButtonInsert" runat="server" 

                                            Text="Insert" CommandName="Add" />

                                </FooterTemplate>

                            </asp:TemplateField>

                            

                            

                             <asp:TemplateField HeaderText="ID" 

                                        SortExpression="Cat ID">

                                <ItemTemplate>

                                    <asp:Label ID="lblcatId" runat="server" 

                                               Text='<%#Eval("catId") %>'>

                                    </asp:Label>

                                </ItemTemplate>

                                <EditItemTemplate>

                                    <asp:TextBox ID="TextCatId" runat="server" 

                                                 Text='<%#Bind("catId") %>'>

                                    </asp:TextBox>

                                </EditItemTemplate>

                                <FooterTemplate>

                                    <asp:TextBox ID="TextCatId" runat="server">

                                    </asp:TextBox>

                                </FooterTemplate>

                         </asp:TemplateField> 

                            

                           <asp:TemplateField HeaderText="Acs Name" 

                                        SortExpression="Acs Name">

                                <ItemTemplate>

                                    <asp:Label ID="lblAcsName" runat="server" 

                                               Text='<%#Eval("acsName") %>'>

                                    </asp:Label>

                                </ItemTemplate>

                                <EditItemTemplate>

                                    <asp:TextBox ID="TextAcsName" runat="server" 

                                                 Text='<%#Bind("acsName") %>'>

                                    </asp:TextBox>

                                </EditItemTemplate>

                                <FooterTemplate>

                                    <asp:TextBox ID="TextAcsName" runat="server">

                                    </asp:TextBox>

                                </FooterTemplate>

                         </asp:TemplateField> 

                         

                         <asp:TemplateField HeaderText="ImageUrl" 

                           SortExpression="ImageUrl">

                                <ItemTemplate>

                                <asp:Label ID="lblImageUrl" runat="server" 

                                           Text='<%#Eval("imgUrl") %>'>

                                </asp:Label>

                                </ItemTemplate>

                                <EditItemTemplate>

                                <asp:TextBox ID="TextImageUrl" runat="server" 

                                             Text='<%#Bind("imgUrl") %>'>

                                </asp:TextBox>

                                </EditItemTemplate>

                                <FooterTemplate>

                                <asp:TextBox ID="TextImageUrl" runat="server">

                                </asp:TextBox>

                                </FooterTemplate>

                        </asp:TemplateField>                      

                        <asp:CommandField  ShowEditButton="True" />

                          

                        <asp:CommandField ShowDeleteButton="True" />

                  </Columns>

           </asp:GridView> 

        VB Code


      Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

            If e.CommandName = "Add" Then

                Dim strcatId As String = DirectCast(GridView1.FooterRow.FindControl("TextCatId"), TextBox).Text()


                Dim strAcsName As String = DirectCast(GridView1.FooterRow.FindControl("TextAcsryName"), TextBox).Text()


                Dim strImageUrl As String = DirectCast(GridView1.FooterRow.FindControl("TextImageUrl"), TextBox).Text()


                SqlDataSource1.InsertParameters("catId").DefaultValue = strcatId

                SqlDataSource1.InsertParameters("acsName").DefaultValue = strAcsName

                SqlDataSource1.InsertParameters("imgUrl").DefaultValue = strImageUrl

               

                SqlDataSource1.Insert()


            End If


        End Sub



    Please any body reply soon.....


    thank u


    Thursday, September 9, 2010 1:13 AM
  • User1716267170 posted

    I think you need to handle the null values to ensure it works correctly as described in "Correctly Handling NULL Values" part here:

    http://www.asp.net/data-access/tutorials/implementing-optimistic-concurrency-with-the-sqldatasource-vb

    Thanks. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 9, 2010 2:01 AM