Reputation: 17373
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
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
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