Mike Simo

Mike Simo

  • NA
  • 17
  • 12.4k

Must declare the scalar variable

Jul 1 2014 11:37 PM
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)