Đang chuẩn bị liên kết để tải về tài liệu:
Executing Multiple SQL Statements

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

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 mySqlConnection.CreateCommand mySqlCommand.CommandText 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 Customers.CustomerlD CompanyName OrderlD FROM Customers Orders WHERE Customers.CustomerlD Orders.CustomerlD AND Customers.CustomerlD ALFKI To run earlier SQL statements you call the ExecuteReader method which returns a SqlDataReader object SqlDataReader mySqlDataReader .

Đã 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.