打印本文 打印本文 关闭窗口 关闭窗口
第三课 SqlCommand对象(翻译)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数14793  更新时间:2007/11/14 13:12:47  文章录入:mintao  责任编辑:mintao

This code is part of the GetNumberOfRecords method of Listing 1 in the Putting it All Together section later in this lesson.

这些代码在表GetNumberOfRecords方法的一部分,我们将在后面集中介绍它。

Putting it All Together

集中介绍

For simplicity, we showed snippets of code in previous sections to demonstrate the applicable techniques .  It is also useful to have an entire code listing to see how this code is used in a working program.  Listing 1 shows all of the code used in this example, along with a driver in the Main method to produce formatted output.

为了简单,我们在前面的小节中展示了一部分代码。它同样对于如何在工程程序中使用是有帮助的。表1显示了在这个例子所使用的所有代码,并通过Main方法中产生格式化的输出。

Listing 1.  SqlConnection Demo

 using System;
 using System.Data;
 using System.Data.SqlClient;
 
 /// <summary>
 ///
Demonstrates how to work with SqlCommand objects
 
/// </summary>
 
class SqlCommandDemo
 {
     SqlConnection conn;
 
 
    public SqlCommandDemo()
     {
         // Instantiate the connection
 
        conn = new SqlConnection(
            "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");
     }
 
 
    // call methods that demo SqlCommand capabilities
 
    static void Main()
     {
         SqlCommandDemo scd = new SqlCommandDemo();
 
         Console.WriteLine();
         Console.WriteLine("Categories Before Insert");
         Console.WriteLine("------------------------");
 
 
        // use ExecuteReader method
 
        scd.ReadData();
 
 
        // use ExecuteNonQuery method for Insert
 
        scd.InsertData();
     &nbs

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

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