Anthony Knight
Anthony Knight

Reputation: 63

Error Procedure getSearch has no parameters and arguments were supplied

I am developing a simple search page that runs off a stored procedure, but I keep getting this error:

Procedure getSearch has no parameters and arguments were supplied.

This is my stored procedure:

ALTER PROCEDURE [dbo].[getSearch] 
AS
BEGIN
   Declare @ProjectCode varchar;

   SELECT [name],[address],[results]
   FROM [myTb]
   WHERE [name] like '%' + @ProjectCode + '%'
   ORDER BY [name] ASC
END

...this is my code:

protected void Button1_Click(object sender, EventArgs e)
{
        DataSet ds = new DataSet();

        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ToString()))
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "getSearch";
                command.Connection = connection;

                command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text);

                connection.Open();
                SqlDataAdapter a = new SqlDataAdapter(command);
                a.Fill(ds);
            }
        }

        gvResults.DataSource = ds;
        gvResults.DataBind();
    } 

The design:

<div style="width: 375px; height: 66px">
    <asp:TextBox ID="TbProjectCode" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search" /><br />
</div>
<div>
    <asp:GridView ID="gvResults" runat="server" Width="718px"></asp:GridView>
</div>

Could I please get some help as to what the issue is with my stored procedure? I was following an example from a previous post, however, I'm still getting this error.

Upvotes: 0

Views: 6981

Answers (2)

Saurabh Sinha
Saurabh Sinha

Reputation: 1373

I also face same issue when i tried below query

Exec procedure_name GO

The correct one must be

Exec procedure_name
GO

Upvotes: 0

Khan
Khan

Reputation: 18162

The syntax on your stored procedure is incorrect.

Try the following. The parameter declaration should fall in parentheses after the procedure name.

I would also suggest giving your parameter a length. E.g. VARCHAR(20)

ALTER PROCEDURE [dbo].[getSearch]
(
    @ProjectCode varchar
)
AS
BEGIN

  SELECT [name],[address],[results]
  FROM [myTb]
  WHERE [name] like '%' + @ProjectCode + '%'
  ORDER BY [name] ASC

END

Upvotes: 4

Related Questions