开发者

The variable name '@Param' has already been declared

开发者 https://www.devze.com 2023-03-08 15:51 出处:网络
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.

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 
       ORDE开发者_C百科R BY ReportType Desc";
   DS.SelectParameters.Add("Param", searchTxtBox.Text.Replace("'", "''"));
   DS.DataBind();
   ListView1.DataBind();               
}


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("'", "''"));


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消