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.

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.