using System; using System; using System.Data; using System.Data.SqlClient; namespace Client.MesExemples.com { class UsingADataReader { static void Main(string[] args) { // Création de la chaîne de connexion SqlConnection connection = new SqlConnection(@"Data Source=(local);" + "Initial Catalog = Contacts;" + "Integrated Security=true"); // Ouvrir la connexion connection.Open(); // Executer une commande SQL SqlCommand MyCommand = new SqlCommand("SELECT * FROM Clients", connection); SqlDataReader MyDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection); while (MyDataReader.Read()) { Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]); } connection.Close(); } } } |
0