foreach (ListItem li in ListBox1.Items)
{
SqlConnection con = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true");
const string SQL = "SELECT EventName FROM Event)";//the result of this statement to be stored in a string
if (li.Selected = //the string)//compare here
{
Response.Redirect("asd.aspx?name=" + a);//at here i want to use the compared value
}
}
I want to store the details from the above SQL statement into a string and compare it with
the item that is selected in the listbox. Upon comparison, if they are equal I want to response.redirect the compared a label in another page.
So you need to execute that SQL and get the result back:
Also, since neither the connection nor the SQL you execute seem to be dependant on anything in the loop – don’t unnecessarily do this SQL statement over and over again! Do it once before the loop and store the result…