2
Answers

Must declare the scalar variable

Mike Simo

Mike Simo

10y
837
1
Hi

In my below code i am getting a blue line under the session 'SearchValue' in the line:

DAsearch.SelectCommand.Parameters.AddWithValue("@Wtags", SearchValue); . and the error message is:

Must declare the scalar variable "@Wtags".



var location = Convert.ToString(Session["location"]);
var cat = Convert.ToString(Session["SearchValue"]);

if (Session["location"] != null)
{

using (SqlConnection srchsql = new SqlConnection(sc))
{

srchsql.Open();


SqlDataAdapter DAsearch = new SqlDataAdapter("SELECT [AdsID],[AdsTit], SUBSTRING([AdsDesc],1,155) as AdsDesc, [Section], [Category], [Wtags], [Country], [State], [City] FROM [ads] WHERE (([Country] = @Country) AND ([Wtags] = @Wtags))", sc);


DataSet DSsrchP = new DataSet();


DAsearch.SelectCommand.Parameters.AddWithValue("@Country", location);
DAsearch.SelectCommand.Parameters.AddWithValue("@Wtags", SearchValue);


DAsearch.Fill(DSsrchP);


resultshowlistview.DataSource = DSsrchP.Tables[0];
resultshowlistview.DataBind();
}
}
else
{

}




Answers (2)
Next Recommended Forum