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.
精彩评论