TAILIEUCHUNG - Executing SELECT Statements and TableDirect Commands phần 1

Executing SELECT Statements and TableDirect Commands A TableDirect command is actually a SELECT statement that returns all the rows and columns for a specified table. | Executing SELECT Statements and TableDirect Commands A TableDirect command is actually a SELECT statement that returns all the rows and columns for a specified table. A Command object has three methods you can use to execute a SELECT statement or TableDirect command. Table shows these methods which you ll learn how to use in the following sections. Table METHODS THAT RETRIEVE INFORMATION FROM THE DATABASE METHOD RETURN TYPE DESCRIPTION ExecuteReader SqlDataReader Used to execute SQL SELECT statements TableDirect commands or stored procedure calls that return a result set. Returns the result set in a DataReader object. ExecuteScalar object Used to execute SQL SELECT statements that return a single value any other values are ignored . Returns the single value as an object. ExecuteXmlReader XmlReader Used to execute SQL SELECT statements that return XML data. Returns the result set in an XmlReader object. Applies only to the SqlCommand class. Executing a SELECT Statement Using the ExecuteReader Method Let s take a look at an example that executes a SELECT statement using the ExecuteReader method. This method returns the result set in a DataReader object which you can then use to read the rows returned by the database. For example the following code creates the required objects and executes a SELECT statement that retrieves the top five rows from the Customers table SqlConnection mySqlConnection new SqlConnection server localhost database Northwind uid sa pwd sa SqlCommand mySqlCommand SELECT TOP 5 CustomerlD CompanyName ContactName Address FROM Customers ORDER BY CustomerlD SqlDataReader mySqlDataReader Tip You ll notice that I didn t call the Open method of the SqlConnection object until just before calling the ExecuteReader method of the SqlCommand object. This is intentional. By opening the connection at the very last moment you minimize time spent .

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.