I have an aspx page, which retrieves data from a table, I have Update, Delete, Cancel buttons. Update works, Cancel works, but Delete does not work, I get error:
Must declare the scalar variable "@UID".

My code looks like this:

<asp:SqlDataSource ID="sdsDetail" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString%>"
        DeleteCommand="DELETE FROM [table] WHERE [UID] = @UID" 
        SelectCommand="SELECT  UID, a, b, c FROM [table] WHERE ([UID] = @UID)"
        UpdateCommand="UPDATE [table] SET [a] = @a, [b] = @b, [c] = @c WHERE [UID] = @UID">
        <SelectParameters>
            <asp:QueryStringParameter Name="UID" QueryStringField="UID" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:QueryStringParameter Name="UID" QueryStringField="UID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="a" />
            <asp:Parameter Name="b" />
            <asp:Parameter Name="c" />
        </UpdateParameters>
     
    </asp:SqlDataSource>

Your help is appreciated.

your SELECT as well as other statement should be like :

SelectCommand="SELECT  UID, a, b, c FROM [table] WHERE  [UID] = " & @UID
NOT  SelectCommand="SELECT  UID, a, b, c FROM [table] WHERE ([UID] = @UID)"

Also you must initialize a value to @UID

Thank you
Postmaster
<snipped>

your SELECT as well as other statement should be like :

SelectCommand="SELECT  UID, a, b, c FROM [table] WHERE  [UID] = " & @UID
NOT  SelectCommand="SELECT  UID, a, b, c FROM [table] WHERE ([UID] = @UID)"

Also you must initialize a value to @UID

Thank you
Postmaster
<snipped>

Thank you! I did not assign data key. :) Thanks.

This article has been dead for over six months. Start a new discussion instead.