Overblog Tous les blogs Top blogs Économie, Finance & Droit Tous les blogs Économie, Finance & Droit
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions

Publicité

DataTable DataReader

DataTable <---> DataReader

 

1 - Charger une DataTable avec un DataReader

            Persistance.OleDb.CONTACT oContact;
            oContact = new Persistance.OleDb.CONTACT();
            Persistance.OleDbConnecte.sCONNECTIONSTRING = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsromagnyMes documentsContacts.mdb";
            System.Data.DataTable oDataTable;
            oDataTable = new DataTable();
 
oDataTable.Load(oContact.ChargerCONTACTs()); //oContact.ChargerCONTACTs() est une méthode retournant un datareader
             // Affichage
            comboBox1.DataSource = oDataTable;
            comboBox1.ValueMember = "nom_contact";

 
2 - Créer un DataReader(avec System.Data.Common.DbDataReader)à partir d’une DataTable

            System.Data.Common.DbDataReader oDbDataReader;
            oDbDataReader = oDataTable.CreateDataReader();
            while (oDbDataReader.Read())
            {
                comboBox2.Items.Add(oDbDataReader["nom_contact"]);
            }
            oDbDataReader.Close();

 

 

Publicité
Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article