Problème d'affichage de mon DropDownList

Leader2000 Messages postés 184 Date d'inscription mercredi 24 mai 2006 Statut Membre Dernière intervention 28 août 2015 - 5 juil. 2013 à 15:07
Leader2000 Messages postés 184 Date d'inscription mercredi 24 mai 2006 Statut Membre Dernière intervention 28 août 2015 - 5 juil. 2013 à 15:10
Bonjour!

Je n'arrive pas à voir les données du champ "au_lname" et quand je clique sur le boutton "connect". Il y a ce message qui vient:
ExecuteReader requires an open and available Connection. The connection's current state is closed.


























------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class ConnectionTester : System.Web.UI.Page
{
protected void cmdConnect_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = @"Data Source=localhost\SQLEXPRESS;" + "Initial Catalog=Master;Integrated Security=SSPI";


// Define the ADO.NET Connection object.
string connectiongString = WebConfigurationManager.ConnectionStrings["Master"].ConnectionString;
//SqlConnection myConnection = new SqlConnection(connectiongString);

try
{
using (myConnection)
{
// Try to open the connection.
myConnection.Open();
lblInfo.Text = " Server Version: " + myConnection.ServerVersion;
lblInfo.Text + = "
Connection Is:" + myConnection.State.ToString();
}
}
catch (Exception err)
{
// Handle an error by displaying the information.
lblInfo.Text = "Error reading the database.";
lblInfo.Text += err.Message;
}
lblInfo.Text += "
Now Connection Is: ";
lblInfo.Text + = myConnection.State.ToString();


SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "SELECT * FROM Authors ORDER BY au lname ";


//myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
myReader.Read();
lstNames.Items.Add(myReader["au_lname"] + "," + myReader["au_fname"]);
myReader.Close();
myConnection.Close();


}

}



Developper est une dimension pour moi.
Leader2000

1 réponse

Leader2000 Messages postés 184 Date d'inscription mercredi 24 mai 2006 Statut Membre Dernière intervention 28 août 2015
5 juil. 2013 à 15:10
Je m'excuse. Il ne s'agit pas du non affichage de mon DropDownList. Au contraire, il s'agit du non affichage des données...


Developper est une dimension pour moi.
Leader2000
0
Rejoignez-nous