intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Creating a Sqldatareader Objec

Chia sẻ: Tuan Nghia | Ngày: | Loại File: PDF | Số trang:1

67
lượt xem
7
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

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.

Chủ đề:
Lưu

Nội dung Text: Creating a Sqldatareader Objec

  1. 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. For example, the following code creates the required objects and executes a SELECT statement that retrieves the top five rows from the Products table of the SQL Server Northwind database, 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 stored in the productsSqlDataReader object. You'll see how to use productsSqlDataReader in the following section.
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2