变量名“@Param”已经声明 [英] The variable name '@Param' has already been declared

查看:484
本文介绍了变量名“@Param”已经声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击搜索按钮2倍以上,我歌厅给定code以下错误消息。可能有人请帮助我在做什么错了。


  

变量名@Param早已
  被宣布。变量名必须是
  查询批处理内唯一或存储
  流程。


 保护无效btnSearch_Click(对象发件人,EventArgs的发送)
{
    DS.SelectCommand =
      选择REPORTNAME,的ReportType,
       从表
       WHERE REPORTNAME LIKE @param
       ORDER BY说明的ReportType;
   DS.SelectParameters.Add(参数,searchTxtBox.Text.Replace(','));
   DS.DataBind();
   ListView1.DataBind();
}


解决方案

尝试

  DS.SelectCommand =
    选择REPORTNAME,的ReportType,
     从表
     WHERE REPORTNAME LIKE @param
     ORDER BY说明的ReportType;
DS.SelectParameters.Clear();
DS.SelectParameters.Add(参数,searchTxtBox.Text.Replace(','));

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();               
}

解决方案

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

这篇关于变量名“@Param”已经声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆