SqlDataSource Delete Parameters and BoundFields

I recently ran across an issue that took a while to resolve, but really shouldn’t have.

I have an SqlDataSource which I’m purposefully using an UPDATE statement for in the DeleteCommand, like this:

DeleteCommand="UPDATE [dbo].[UDIC_EquipInventory]
                        SET [Status] = '6'
                            ,[AssignedTo] = ''
                            ,[RetiredDate] = GetDate()
                            ,[LastEditDate] = GetDate()
                            ,[LastOperator] = @LastOperator
                         WHERE UnitID = @unitid"

I have both the parameters there included properly like this:

<DeleteParameters>
            <asp:Parameter Name="unitid" DbType="String" />
            <asp:SessionParameter Name="LastOperator" SessionField="SignedInEmployeeId" DbType="String" />
 </DeleteParameters>

 

However every time I tried to use the DeleteCommand on my Telerik RadGrid tied to this datasource, I received the error “Must declare the scalar variable @LastOperator”.

 

It turns out according to this MSDN article on Delete Parameters, a parameter CANNOT be the same name as a boundfield representing this column.

I simply changed the parameter name in my query and DeleteParameters sections, and now it works!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.