Hi guys,
I'm hoping you can help me find a more elegant solution to my query inside a foreach loop. Here is the loop in question:
foreach (DataRow row in dt_blah.Rows)
{
SqlCommand sc = con.CreateCommand();
sc.CommandType = CommandType.Text;
sc.CommandText = "select blah blah blah .. where S = @s1 and p = @p1";
sc.Parameters.AddWithValue("@s1", ddl.SelectedValue);
sc.Parameters.AddWithValue("@p1", row["Category"]);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(sc);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
}
the problem is that the query relies on the value of each "Category" row in the dt_blah table. I have ran the query as a standalone and it does not even take a second, so I believe i'm safe to say that it is not my query that needs modifying. Have you guys encountered this kind of issue? and if so can you offer any valid solutions?
Thank you for your time and help.