locked
must declare the scalar variable? RRS feed

  • Question

  • User-566823024 posted

    im having this prob, when deleting a line from my gridview, this error shows out.

    Must declare the scalar variable "@productid".

    Well, i dont know whats wrong with the coding. As i have already declared the productid.

     <table style="width:100%;">
                
                 <tr>
                        <td class="style24" colspan="2">
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                DeleteCommand="DELETE FROM [product] WHERE productid = @productid" 
                                InsertCommand="INSERT INTO [product]([productid], [productname], [productdesc], [productprice]) VALUES (@productid, @productname, @productdesc, @productprice)" 
                                SelectCommand="SELECT * FROM [product]" 
                                UpdateCommand="UPDATE [product] SET [productid] = @productid, [productname] = @productname, [productdesc] = @productdesc, [productprice] = @productprice WHERE [productid] = @productid">
                                <DeleteParameters>
                                    <asp:Parameter Name="productid" />
                                </DeleteParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="productid" />
                                    <asp:Parameter Name="productname" />
                                    <asp:Parameter Name="productdesc" />
                                    <asp:Parameter Name="productprice" />
                                </UpdateParameters>
                                <InsertParameters>
                                    <asp:Parameter Name="productid" />
                                    <asp:Parameter Name="productname" />
                                    <asp:Parameter Name="productdesc" />
                                    <asp:Parameter Name="productprice" />
                                </InsertParameters>
                            </asp:SqlDataSource>
                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onDeleteCommand="GridView1_onDeleteCommand"
                                DataSourceID="SqlDataSource1">
                                <Columns>
                                    <asp:BoundField DataField="productid" HeaderText="productid" InsertVisible="False" ReadOnly="True"
                                        SortExpression="productid" />
                                        <asp:ImageField DataImageUrlField="productid" DataImageUrlFormatString="~/images/product/{0}.jpg">
                        </asp:ImageField>
                                    <asp:BoundField DataField="productname" HeaderText="productname" 
                                        SortExpression="productname" />
                                    <asp:BoundField DataField="productdesc" HeaderText="productdesc" 
                                        SortExpression="productdesc" />
                                    <asp:BoundField DataField="productprice" HeaderText="productprice" 
                                        SortExpression="productprice" />
                                    
                                
                                    
    <asp:CommandField ShowEditButton="True" />
    <asp:CommandField DeleteImageUrl="~/images/product/{0}.jpg" 
                                        ShowDeleteButton="True" />
      </Columns>
                            </asp:GridView>
                            
                            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
                    Height="51px" Width="348px" DefaultMode="Insert">
                    <Fields>
                        <asp:TemplateField HeaderText="Image">
                            <InsertItemTemplate>
                                <asp:FileUpload ID="FileUpload2" runat="server" Width="196px" /> 
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="productid" HeaderText="productid" 
                            SortExpression="productid" />
                        <asp:BoundField DataField="productname" HeaderText="productname" 
                            SortExpression="productname" />
                        <asp:BoundField DataField="productdesc" HeaderText="productdesc" 
                            SortExpression="productdesc" />
                        <asp:BoundField DataField="productprice" HeaderText="productprice" 
                            SortExpression="productprice" />
                        <asp:CommandField NewText="Insert" ShowInsertButton="True" ShowCancelButton="False" CancelText="" />
                    </Fields>
                </asp:DetailsView>
                        </td>
                    </tr>
                </table>

    thanks in advance

    Tuesday, April 6, 2010 6:46 PM

Answers

  • User-442214108 posted

    try setting the DataKeys property on the control where the ProductID is supposed to come from  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 6, 2010 8:32 PM

All replies

  • User-442214108 posted

    try setting the DataKeys property on the control where the ProductID is supposed to come from  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 6, 2010 8:32 PM
  • User-566823024 posted

    yea! that works!TQ!

    Tuesday, April 6, 2010 8:35 PM