传递连接给command对象 SqlCommand cmd = new SqlCommand("select * from Customers", conn); // // 4. Use the connection使用连接 //
// get query results得到查询结果 rdr = cmd.ExecuteReader(); // print the CustomerID of each record打印每条记录的CustomerID while (rdr.Read()) { Console.WriteLine(rdr[0]); } } finally { // close the reader关闭reader if (rdr != null) { rdr.Close(); } // 5. Close the connection关闭连接 if (conn != null) { conn.Close(); } } } }