TAILIEUCHUNG - Executing Multiple SQL Statements

Executing Multiple SQL Statements Typically, your C# program and the database will run on different computers and communicate over a network. Each time you execute a command in your program | Executing Multiple SQL Statements Typically your C program and the database will run on different computers and communicate over a network. Each time you execute a command in your program it has to travel over the network to the database and be executed by the database and any results must be sent back across the network to your program. That s a lot of network traffic One way to potentially reduce network traffic is to execute multiple SQL statements at a time. In this section you ll see how to execute multiple SELECT statements and retrieve results and you ll see how to execute multiple SELECT INSERT UPDATE and DELETE statements that are interleaved. Executing Multiple SELECT Statements Let s take a look at how you execute multiple SELECT statements and retrieve the results. The following code first creates a SqlCommand object named mySqlCommand and sets its CommandText property to three different SELECT statements SqlCommand mySqlCommand SELECT TOP 5 ProductID ProductName FROM Products ORDER BY ProductID SELECT TOP 3 CustomerID CompanyName FROM Customers ORDER BY CustomerID SELECT TOP 6 OrderID CustomerID FROM Orders ORDER BY OrderID Notice that all of the SELECT statements are separated by semi-colons. Using Table Joins Be careful to retrieve only the rows and columns you actually need. Also make sure you use SELECT statements that retrieve rows from multiple tables. For example if you want to see all the orders placed by the customer with the CustomerID of ALFKI don t perform two separate SELECT statements against the Customers and Orders tables. Instead use a table join as shown in the following SELECT statement SELECT CompanyName OrderlD FROM Customers Orders WHERE AND ALFKI To run earlier SQL statements you call the ExecuteReader method which returns a SqlDataReader object SqlDataReader mySqlDataReader .

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.