none
SqlDataSource can't find Delete parameter when DeleteCommandType="StoredProcedure" RRS feed

  • Question

  • I have a GridView bound to a SqlDataSource.  The Delete command of the SqlDataSource points to a stored procedure that takes one parameter.  I created the Parameter element within the DeleteParameters element, but each time I execute the delete function I get the following error:

     

    Procedure 'sp_RemoveUser' expects parameter '@UserName', which was not supplied.

     

    Can anyone see what I am doing wrong?  Can anyone provide an example of how to delete with a stored procedure that takes a parameter?

     

    The code follows:

     

    Code Snippet

    <asp:GridView ID="gvMembership" runat="server"

      DataSourceID="dsMembership"

      EmptyDataText="No Data"

      AllowPaging="True"

      AutoGenerateEditButton="True"

      AutoGenerateDeleteButton="True"

      BackColor="White"

      BorderColor="#999999"

      BorderStyle="None"

      BorderWidth="1px"

      CellPadding="3"

      GridLines="Vertical">

      <FooterStyle BackColor="#CCCCCC"

        ForeColor="Black" />

      <RowStyle BackColor="#EEEEEE"

        ForeColor="Black" />

      <PagerStyle BackColor="#999999"

        ForeColor="Black"

        HorizontalAlign="Center" />

      <SelectedRowStyle BackColor="#008A8C"

        Font-Bold="True"

        ForeColor="White" />

      <HeaderStyle BackColor="#000084"

        Font-Bold="True"

        ForeColor="White" />

      <AlternatingRowStyle BackColor="Gainsboro" />

    </< SPAN>asp:GridView>

     

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

      ConnectionString=""

      SelectCommand="SELECT u.UserName AS   UserName, m.IsApproved AS IsApproved, m.IsLockedOut AS IsLockedOut, m.CreateDate AS CreateDate, m.LastLoginDate AS LastLoginDate, m.LastPasswordChangedDate AS LastPasswordChangedDate, m.LastLockoutDate AS LastLockoutDate, m.FailedPasswordAttemptCount AS FailedPasswordAttemptCount, m.FailedPasswordAttemptWindowStart AS FailedPasswordAttemptWindowStart, m.Comment AS Comment, m.Email AS Email, m.ApplicationId AS ApplicationId, a.ApplicationName AS ApplicationName, m.UserId AS UserId FROM dbo.aspnet_Membership m INNER JOIN dbo.aspnet_Users u ON m.UserId = u.UserId INNER JOIN dbo.aspnet_Applications a ON m.ApplicationId = a.ApplicationId WHERE (a.ApplicationName = N'rChordata')"

      DeleteCommand="sp_RemoveUser"

      DeleteCommandType="StoredProcedure" >

      <DeleteParameters>

        <asp:Parameter Name="UserName" Type="string" />

      </< SPAN>DeleteParameters>

    </< SPAN>asp:SqlDataSource>

     

     

     

     

    The same select statement formatted better:

     

    Code Snippet

    SELECT u.UserName AS UserName,

         m.IsApproved AS IsApproved,

         m.IsLockedOut AS IsLockedOut,

         m.CreateDate AS CreateDate,

         m.LastLoginDate AS LastLoginDate,

         m.LastPasswordChangedDate AS LastPasswordChangedDate,

         m.LastLockoutDate AS LastLockoutDate,

         m.FailedPasswordAttemptCount AS FailedPasswordAttemptCount,

         m.FailedPasswordAttemptWindowStart AS FailedPasswordAttemptWindowStart,

         m.Comment AS Comment,

         m.Email AS Email,

         m.ApplicationId AS ApplicationId,

         a.ApplicationName AS ApplicationName,

         m.UserId AS UserId

    FROM dbo.aspnet_Membership m INNER JOIN

         dbo.aspnet_Users u ON m.UserId = u.UserId INNER JOIN

         dbo.aspnet_Applications a ON m.ApplicationId = a.ApplicationId

    WHERE (a.ApplicationName = N'rChordata')

     

     

     

    Friday, March 14, 2008 8:35 PM

Answers

  •  

    Matt,

     

    Thanks for the reply.  Actually, I already tried that and got the message:

     

     

    @@UserName is not a parameter for procedure sp_RemoveUser.

     

     

    Apparently, The system adds a "@" to the beginning of the name of the parameter.  Any other ideas?

    • Marked as answer by Dogulas Thursday, April 9, 2009 6:50 PM
    Friday, March 14, 2008 11:28 PM
  • apparently, it was a name clash.  When I changed the name from "UserName" to something else, it began to work.

     

    Wednesday, March 26, 2008 8:24 PM

All replies

  • I would first try this:

     

    <asp:Parameter Name="@UserName" Type="string" />

     

    Might be all you need.
    Friday, March 14, 2008 11:07 PM
  •  

    Matt,

     

    Thanks for the reply.  Actually, I already tried that and got the message:

     

     

    @@UserName is not a parameter for procedure sp_RemoveUser.

     

     

    Apparently, The system adds a "@" to the beginning of the name of the parameter.  Any other ideas?

    • Marked as answer by Dogulas Thursday, April 9, 2009 6:50 PM
    Friday, March 14, 2008 11:28 PM
  • apparently, it was a name clash.  When I changed the name from "UserName" to something else, it began to work.

     

    Wednesday, March 26, 2008 8:24 PM