1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public string ChaîneConnection;
public SqlConnection Connect;
public SqlCommand Cmd;
public string req;
public SqlDataAdapter repDA;
System.Data.DataSet repDS;
private void Form2_Load(object sender, System.EventArgs e)
{
try
{
ChaîneConnection = "Integrated security=SSPI;Persist Security Info=False;Initial Catalog=Livraison;Data Source=PC-DE-TIMA\\SQLEXPRESS";
Connect = new SqlConnection(ChaîneConnection);
Connect.Open(); //ouverture de la connexion par méthode Open
Cmd = Connect.CreateCommand(); //instanciation de commande à partir de la connexion
req = "SELECT CLI_CODE FROM CLIENT";
Cmd.CommandText = req; //affectation d'une requete sql à la propriété CommandText
repDA = new SqlDataAdapter();
repDA.SelectCommand = Cmd;
repDS = new DataSet();
repDA.Fill(repDS, "CLIENT");
liste.DataSource = repDS.Tables["CLIENT"]; //remplissage du combobox
liste.DisplayMember = "CLI_CODE";
Connect.Close();
}
catch (Exception ex)
{
//afficher le message correspondant
System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
}
} |
Partager