Danh mục

Creating a Sqldatareader Objec

Số trang: 1      Loại file: pdf      Dung lượng: 11.00 KB      Lượt xem: 14      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (1 trang) 0

Báo xấu

Xem trước 1 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Creating a SqlDataReader Object You can create a DataReader object only by calling the ExecuteReader() method of a Command object. Command objects were covered in the previous chapter.
Nội dung trích xuất từ tài liệu:
Creating a Sqldatareader ObjecCreating a SqlDataReader ObjectYou can create a DataReader object only by calling the ExecuteReader() method of aCommand object. Command objects were covered in the previous chapter. For example,the following code creates the required objects and executes a SELECT statement thatretrieves the top five rows from the Products table of the SQL Server Northwinddatabase, storing the returned rows in a SqlDataReader object:SqlConnection mySqlConnection = new SqlConnection( server=localhost;database=Northwind;uid=sa;pwd=sa );SqlCommand mySqlCommand = mySqlConnection.CreateCommand();mySqlCommand.CommandText = SELECT TOP 5 ProductID, ProductName, UnitPrice, + UnitsInStock, Discontinued + FROM Products + ORDER BY ProductID;mySqlConnection.Open();SqlDataReader productsSqlDataReader = mySqlCommand.ExecuteReader();Notice that the SqlDataReader object returned by the ExecuteReader() method is storedin the productsSqlDataReader object. Youll see how to use productsSqlDataReader inthe following section.

Tài liệu được xem nhiều: