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.
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 staticvoid 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