Bạn không thể khôi phục lại cơ sở dữ liệu Northwind, bởi vì các loại khôi phục lại bạn đang làm đòi hỏi độc quyền Thực hiện dự án này khởi động, và chạy nó với Ctrl + F5. Bạn sẽ thấy kết quả hiển thị trong hình 8-4. | CHAPTER 6 INTRODUCING COMMANDS 131 Figure 6-6. Executing statements How It Works In this program you use a scalar query and two statements storing the SQL in three string variables define scalar query string sqlqry @ select count from employees define insert statement string sqlins @ insert into employees firstname lastname values Zachariah Zinn define delete statement 132 CHAPTER 6 INTRODUCING COMMANDS string sqldel @ delete from employees where firstname Zachariah and lastname Zinn Then you create two commands. The first is cmdqry which encapsulates the scalar query to count the rows in the Employees table. You use this command several times to monitor the number of rows as you insert and delete employees. The second is cmdnon which you use twice first to insert a row then to delete the same row. You initially set its CommandText to the INSERT statement SQL SqlCommand cmdnon new SqlCommand sqlins conn and later reset it to the DELETE statement SQL sqldel executing the SQL statements with two calls to ExecuteNonQuery returns an int indicating how many rows are affected by the command. Since you want to display the number of affected rows you put the call to ExecuteNonQuery within a call to . You use ExecuteScalar to display the number of rows before and after the INSERT and DELETE operations After INSERT Number of Employees is 0 Note that both cmdqry and cmdnon are SqlCommand objects. The difference between submitting queries and statements is the method you use to submit them. Note With ExecuteNonQuery you can submit virtually any SQL statement including Data Definition Language DDL statements to create and drop database objects such as tables and indexes. We ll create tables in Chapter 11 using SSMSE because that s how they re typically created but the SQL you learn there can be submitted from a C program with ExecuteNonQuery . CHAPTER 6 INTRODUCING COMMANDS