SVP, j'ai eu un problème lors de l'exécution d'une application que je suis entrain de faire ... j'ai une exception "Un DataReader associé à cette commande est déjà ouvert. Il doit d'abord être fermé." je sais pas lequel et où dois je le fermer .. j'ai essayé bcp de close() mais rien ne se change
voilà le code:
Code C# :
protected void Button2_Click(object sender, EventArgs e)
{
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "...";
connection.Open();
if (connection.State == ConnectionState.Open)
{
SqlCommand com = new SqlCommand("....'");
com.Connection = connection;
if (com.ExecuteReader().HasRows)
{
Label2.Visible = true;
}
else
{
Label2.Visible = false;
SqlCommand sqlcom = new SqlCommand(" INSERT ....");
sqlcom.Connection = connection;
sqlcom.ExecuteNonQuery();
string Req2 = "Select ID_p... where Nom_p ='" + this.TextBox1.Text + "'";
SqlCommand sqlcom0 = new SqlCommand(Req2, connection);
SqlDataReader rd0 = sqlcom0.ExecuteReader();
int idp =0;
if (rd0.Read())
idp = (int)rd0["ID_p"];
rd0.Close();
for (int i = 0; i < GridView2.Rows.Count; i++)
{
string Req = "Select ID_d ...."'";
rd0.Close();
SqlCommand sqlcom1 = new SqlCommand(Req, connection);
SqlDataReader rd1 = sqlcom1.ExecuteReader();
GridViewRow row = GridView2.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chk1")).Checked;
if (isChecked)
{
rd0.Close();
int idd=0 ;
if (rd1.Read())
{
rd0.Close();
idd = (int)rd1["ID_d"];
rd1.Close();
SqlCommand sqlcom2 = new SqlCommand(" INSERT INTO ....)");
sqlcom2.Connection = connection;
sqlcom2.ExecuteNonQuery();
Response.Redirect("WebForm6.aspx");
}
rd1.Close();
}
rd0.Close();
rd1.Close();
}
Label1.Text = "Un nouveau projet a été ajouté .. ";
Label1.Visible = true;
}
}
}
catch (Exception E) { }