1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Creating a Sqldatareader Objec ppt

1 202 0
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Creating a SqlDataReader Object
Thể loại Tài liệu
Định dạng
Số trang 1
Dung lượng 11 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Creating a Sg/DataReader 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.. F

Trang 1

Creating a Sg/DataReader 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";

mySqlConnecfion.Open();

SqlDataReader productsSalDataReader =

mySqlCommand.ExecuteReader();

Notice that the SqlDataReader object returned by the ExecuteReader() method is stored

in the productsSq]DataReader object You'll see how to use productsSqlDataReader in the following section

Ngày đăng: 21/01/2014, 07:20

TỪ KHÓA LIÊN QUAN