ps : i tried to close connexions and datareaders but it didn't work , also tried the previous solutions here but still got the error i even separed the connexions and it didn't work as well what i'm trying to do here is to read an id from a table from the sql server and use that id to look for another data in another table but it always give me the closing connexion or data problem
SqlConnection cnx = new SqlConnection("data source = . ; database = tnt ; integrated security = true ; MultipleActiveResultSets=true");
SqlConnection cnx2 = new SqlConnection("data source = . ; database = tnt ; integrated security = true ; MultipleActiveResultSets=true");
SqlCommand cmd = new SqlCommand("select matricule from inscription where numformation = @n",cnx);
cmd.Parameters.AddWithValue("@n", comboBox2.Text);
SqlDataReader dr = cmd.ExecuteReader();
List<string> hawhaw = new List<string>();
while (dr.Read())
{
hawhaw.Add(dr[0].ToString());
}
cmd.Dispose();
cnx2.Close();
cnx2.Open();
SqlCommand cmd2 = new SqlCommand("select * from person where matricule = @m", cnx2);
foreach (var item in hawhaw)
{
cmd2.Parameters.Clear();
cmd2.Parameters.AddWithValue("@m", item);
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
MessageBox.Show(dr2[0].ToString());
}
}
cmd2.Dispose();
cnx.Close();