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

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

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