Probleme d'afficher plusieurs retour du requetes dans un meme methode sur un web page
Salut tout le monde,
J'ai un probleme de prendre 2 retours du 2 requetes du database et les mettre dans le webpage ASP.NET.
Le probleme
Citation:
There is already an open DataReader associated with this Command which must be closed first
qui est mit sur la ligne
Code:
DropDownList3.DataSource = cmd.ExecuteReader();
dans la 2eme partie du code.
J'ai fais changé un peu du code et j'ai ferme la connection du database apres la fin du 1er partie du code c.a.d apres
Code:
dropdownlist.selectindex=-1;
et j'ai l'ouvrir du nouveau dans la 2eme partie du code, mais un nouveau error se vient dans l'instruction
Citation:
Invalid attempt to call FieldCount when reader is closed.
qlq un peut m'aider
bien sur j'ai fait defini le connectionstring correctement mais j'ai pas ecrir dans le code ici,
merci beaucoup
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| string selectsql = "select productname,productID from products";
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(selectsql, con);
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "ProductName";
DropDownList1.DataValueField = "ProductID";
DropDownList1.SelectedIndex = -1;
selectsql = "SELECT ContactName, CustomerID FROM Customers";
cmd = new SqlCommand(selectsql, con);
DropDownList3.DataSource = cmd.ExecuteReader();
DropDownList3.DataTextField = "ContactName";
DropDownList3.DataValueField = "cusomterid";
this.DataBind();
con.Close();
DropDownList3.SelectedIndex = -1; |