using System; using System.Data.OleDb; public class ConnexionBaseExcel { [STAThread] static void Main(string[] args) { String chaineConnexion = @"provider=sqloledb;server=(local);database=MesExemples.com;Integrated Security=SSPI"; String sSQL = "select * from Clients"; OleDbConnection connexion = new OleDbConnection(chaineConnexion); connexion.Open(); OleDbCommand oledComm = new OleDbCommand(sSQL, connexion); OleDbDataReader oledbReader = oledComm.ExecuteReader(); int idxID = oledbReader.GetOrdinal("id"); int idxSociété = oledbReader.GetOrdinal("Société"); int idxAdresse = oledbReader.GetOrdinal("Adresse"); while(oledbReader.Read()) { Console.WriteLine("{0} {1} {2}", oledbReader.GetValue(idxID), oledbReader.GetValue(idxSociété), oledbReader.GetValue(idxAdresse)); } } } |
0