打印本文 打印本文 关闭窗口 关闭窗口
第二课 SqlConnection对象(翻译)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数11088  更新时间:2007/11/14 13:12:47  文章录入:mintao  责任编辑:mintao
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]  ...  下一页 >> 

打印本文 打印本文 关闭窗口 关闭窗口