TAILIEUCHUNG - Beginning C# 2005 Databases From Novice to Professional phần 4

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

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.