SqlCommand

命名空间:   System.Data.SqlClient
程序集:  System.Data(位于 System.Data.dll)

 1 private static void ReadOrderData(string connectionString)
 2 {
 3     string queryString = 
 4         "SELECT OrderID, CustomerID FROM dbo.Orders;";
 5     using (SqlConnection connection = new SqlConnection(
 6                connectionString))
 7     {
 8         SqlCommand command = new SqlCommand(
 9             queryString, connection);
10         connection.Open();
11         SqlDataReader reader = command.ExecuteReader();
12         try
13         {
14             while (reader.Read())
15             {
16                 Console.WriteLine(String.Format("{0}, {1}",
17                     reader[0], reader[1]));
18             }
19         }
20         finally
21         {
22             // Always call Close when done reading.
23             reader.Close();
24         }
25     }
26 }

猜你喜欢

转载自www.cnblogs.com/firstzky/p/9167727.html