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
| public static void Main()
{
string strConnexion = "Data Source=localhost; Integrated Security=SSPI;" + "Initial Catalog=Northwind";
string strRequete = "SELECT CategoryID, CategoryName FROM Categories;" + "SELECT EmployeeID, LastName FROM Employees";
try
{
SqlConnection oConnection = new SqlConnection(strConnexion);
SqlCommand oCommand = new SqlCommand(strRequete,oConnection);
oConnection.Open();
SqlDataReader oReader = oCommand.ExecuteReader();
do
{
Console.WriteLine("\t{0}\t{1}", oReader.GetName(0), oReader.GetName(1));
while (oReader.Read())
{
Console.WriteLine("\t{0}\t{1}", oReader.GetInt32(0), oReader.GetString(1));
}
}
while (oReader.NextResult());
oReader.Close();
oConnection.Close();
}
catch (Exception e)
{
Console.WriteLine("L'erreur suivante a été rencontrée :" + e.Message);
}
} |
Partager