none
Procedure 'SP Name' expects parameter '@Name', which was not supplied-Error

    Question

  •  I used grid view to delete one row.In that time i got the error like "Procedure 'SP Name' expects parameter '@Name', which was not supplied". My code is :

    protected void dgProject_RowDeleting(object sender, GridViewDeleteEventArgs e)

    {

    GridViewRow row = dgProject.Rows[e.RowIndex];

    string a = row.Cells[1].Text;

    string b = row.Cells[2].Text;

    SqlDataSource1.ConnectionString = MyDataBase;

    SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;

    SqlDataSource1.DeleteCommand = "SP Name";

    SqlDataSource1.DeleteParameters.Add("Name", a);

    SqlDataSource1.DeleteParameters.Add("IdNumber", b);

    SqlDataSource1.Delete();

    Bind();

    }

     

    My SP Is:

    set ANSI_NULLS ON

    set QUOTED_IDENTIFIER ON

    go

    ALTER procedure [dbo].[SP Name]

    @Name varchar(50),

    @IdNumber varchar(50)

    as

    delete from nirproject where IdNumber=@IdNumber

     

    I don't Know the problem.Anybody please help about this problem.....

     

     

     

     

    Tuesday, June 26, 2007 12:26 AM

Answers

  • add the prefix @ for all the parameters

     

    SqlDataSource1.DeleteParameters.Add("@Name", a);

    SqlDataSource1.DeleteParameters.Add("@IdNumber", b);

    Tuesday, June 26, 2007 6:33 AM

All replies

  • add the prefix @ for all the parameters

     

    SqlDataSource1.DeleteParameters.Add("@Name", a);

    SqlDataSource1.DeleteParameters.Add("@IdNumber", b);

    Tuesday, June 26, 2007 6:33 AM
  • Thank You for your Information.If i did this It shows the ERROR Like This:

    @@Name is not a parameter for procedure SP Name.

    Tuesday, June 26, 2007 3:07 PM
  • <script runat="server">
    Sub On_Delete(ByVal sender As Object, ByVal e As EventArgs)
        SqlDataSource1.Delete()
    End Sub 'On_Delete
    </script>

    <html  >
        <head>
        <title>ASP.NET Example</title>
    </head>

        <body>
            <form id="form1" runat="server">

                <aspTongue TiedqlDataSource
                    id="SqlDataSource1"
                    runat="server"
                    ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                    SelectCommand="SELECT OrderID FROM Orders"
                    DeleteCommand="DELETE FROM [Order Details] WHERE OrderID=@OrderID;DELETE FROM Orders WHERE OrderID=@OrderID;">
                    <DeleteParameters>
                        <asp:ControlParameter Name="OrderID" ControlId="DropDownList1" PropertyName="SelectedValue" />
                    </DeleteParameters>
                </aspTongue TiedqlDataSource>

                <aspBig SmileropDownList
                    id="DropDownList1"
                    runat="server"
                    DataTextField="OrderID"
                    DataValueField="OrderID"
                    DataSourceID="SqlDataSource1">
                </aspBig SmileropDownList>

                <asp:Button
                    id="Button1"
                    runat="server"
                    Text="Delete Order"
                    OnClick="On_Delete">
                </asp:Button>

            </form>
        </body>
    </html>
    Wednesday, June 27, 2007 5:22 AM
  • Are you sure you did not put double @ signs at the beginning of the parameter names? Could you post actual part of the code that creates these parameters?

    Wednesday, June 27, 2007 10:34 AM
    Moderator
  •  

    Also, it is considered bad practice to begin the stored procedure name with 'SP'  Microsoft has indicated it may prove to be a problem in future releases.

    Wednesday, June 27, 2007 4:26 PM
  • I'm having the same problem but I have the @'s in my code.  Anyone know what the deal is?  Mines tellin me that applicationname doesn't exist?

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(e.Values["TempID"]);
            string username = e.Values["UserName"].ToString();
            //SqlDataSource1.DeleteCommand = "DELETE FROM Users WHERE TempID = '" + id + "'";
           
            SqlDataSource1.DeleteParameters.Add("@ApplicationName",  "UIC");
            SqlDataSource1.DeleteParameters.Add("@UserName", username);
            SqlDataSource1.DeleteParameters.Add("@TablesToDeleteFrom","15");
            SqlDataSource1.DeleteParameters.Add("@NumTablesDeletedFrom", DBNull.Value.ToString());

            SqlDataSource1.DeleteParameters[0].Direction = ParameterDirection.Input;
            SqlDataSource1.DeleteParameters[1].Direction = ParameterDirection.Input;
            SqlDataSource1.DeleteParameters[2].Direction = ParameterDirection.Input;
            SqlDataSource1.DeleteParameters[3].Direction = ParameterDirection.Output;

            SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
            SqlDataSource1.DeleteCommand = "aspnet_Users_DeleteUser";
            SqlDataSource1.Delete();
        }
    Sunday, September 02, 2007 8:07 PM

  • I m not familiar with 2005 if this code belongs to vs2005

    SqlDataSource1.DeleteParameters.Add("Name", a);

    SqlDataSource1.DeleteParameters.Add("IdNumber", b);


    1.Add @ to the parameters

    2.Where is the datatype

    3 cmd.Parameters.Add("@IdNumber", SqlDbType.Int).Value = b

      cmd.Parameters.Add("@Name", SqlDbType.VarChar, 30).Value = a


           Try


                cn = New SqlConnection
                cn.ConnectionString = ConnectionString
                cmd = New SqlCommand
                cmd.Connection = cn
                cmd.CommandText = "del"
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = Trim(Textbox1.Text)
                cmd.Parameters.Add("@name", SqlDbType.VarChar, 30).Value = Trim(Textbox4.Text)
                cn.Open()
                cmd.ExecuteNonQuery()
                lblMessage.Text = "Record Deleted"
                cn.Close()
            Catch ex As Exception
                lblMessage.Text = ex.Message
                cn.Close()
            End Try



    Plz chek it if u get any problem plz reply with the error. I will check out and i will give u one more solution.



    In procedure there is no need of name

    create procedure [dbo].[del]

    @IdNumber varchar(50)

    as

    delete from nirproject where IdNumber= @IdNumber


    Thank u

    Baba

    Monday, September 03, 2007 5:51 AM
  • This is the one error exist in the .net frame work itself.
    In case if u are going to execute the procedure using odbc connection the sp name should be calle din this format.

    "call up_UserValidate(?,?)"

    the above question mark denotes the number of input and output parameters.
    Friday, January 04, 2008 7:37 PM