using System.Data.SqlClient; SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True"); connection.Open();
using System.Data.SqlClient; SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True"); SqlCommand command = new SqlCommand("SELECT * FROM Customer", connection); SqlDataReader reader = command.ExecuteReader(); while(reader.Read()) { Console.WriteLine(reader["FirstName"] + " " + reader["LastName"]); } reader.Close(); connection.Close();This example creates a SqlCommand object that executes a SELECT statement to retrieve data from the Customer table. The SqlDataReader object is then used to read the data returned by the SELECT statement. The data is displayed in the console window. Package Library: System.Data.SqlClient is a part of the .NET Framework Class Library.