| 4. 使用其它的ADO.NET对象执行数据库操作
5. 关闭连接
We''''ve already seen how to instantiate a SqlConnection. The rest of the steps, opening, passing, using, and closing are shown in Listing 1.
我们已经看到如何实例化SqlConnetion。其它的步骤:打开、传递、使用和关闭参见Listing1:
Listing 1. Using a SqlConnection
using System; using System.Data; using System.Data.SqlClient;
/// <summary> /// Demonstrates how to work with SqlConnection objects /// </summary> class SqlConnectionDemo { static void Main() { // 1. Instantiate the connection实例化连接 SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");
SqlDataReader rdr = null;
try { // 2. Open the connection打开连接 conn.Open();
// 3. Pass the connection to a command object 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |