Nil Pun
Nil Pun

Reputation: 17373

The variable name '@Param' has already been declared

I'm geting the following error message for given code when user clicks on search button more than two times. Could some one please help what i'm doing wrong.

The variable name '@Param' has already been declared. Variable names must be unique within a query batch or stored procedure.

protected void btnSearch_Click(object sender, EventArgs e)
{
    DS.SelectCommand = 
      "SELECT ReportName, ReportType, 
       FROM Table 
       WHERE ReportName LIKE @param 
       ORDER BY ReportType Desc";
   DS.SelectParameters.Add("Param", searchTxtBox.Text.Replace("'", "''"));
   DS.DataBind();
   ListView1.DataBind();               
}

Upvotes: 2

Views: 5421

Answers (2)

Bala R
Bala R

Reputation: 108967

TRy

DS.SelectCommand = 
    "SELECT ReportName, ReportType, 
     FROM Table 
     WHERE ReportName LIKE @param 
     ORDER BY ReportType Desc";
DS.SelectParameters.Clear();
DS.SelectParameters.Add("Param", searchTxtBox.Text.Replace("'", "''"));

Upvotes: 5

Simon Steele
Simon Steele

Reputation: 11608

As I can't see where DS is defined I can't be sure, but I suspect you're using the same datasource elsewhere with a different Param. Use a different source for each different query.

Upvotes: 0

Related Questions