I am facing an error message when move to another page in my c# application which this page contain cascading dropdownlist. I didnt know how i can fix it so could you please help me with it.
The parameterized query '(@Country nvarchar(4000))SELECT State FROM State WHERE Country =' expects the parameter '@Country', which was not supplied.
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies.Get("Location");
if (!IsPostBack)
{
if (cookie != null)
{
DataTable StateDT = new DataTable();
using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))
{
// Create the SelectCommand.
SqlCommand command = new SqlCommand("SELECT State FROM State WHERE Country = @Country", con2);
command.Parameters.AddWithValue("@Country", (cookie["Location"]));
SqlDataAdapter adaptar = new SqlDataAdapter();
adaptar.SelectCommand = command;
adaptar.Fill(StateDT);
carstatedrdolst.DataSource = StateDT;
carstatedrdolst.DataTextField = "State";
carstatedrdolst.DataBind();
}
carstatedrdolst.Items.Insert(0, new ListItem("Select State", ""));
}
}
}
I think you need to get values of cookie like