Đang chuẩn bị liên kết để tải về tài liệu:
Microsoft ADO .NET 4 Step by Step - p 20

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Mã này truy cập các bản ghi trong tập thứ hai của kết quả, các câu lệnh SELECT cho bảng OrderEntry, thông qua phương pháp gọi NextResult. 5. Khởi động chương trình. Về hình thức quản lý khách hàng, hãy chọn một khách hàng từ danh sách các khách hàng và sau đó nhấp vào Xem đơn đặt hàng. | 166 Microsoft ADO.NET 4 Step by Step 4. Just after the Read the next set which contains the orders comment add the following code customerReader.NextResult Do While customerReader.Read True oneOrder New OrderInfo oneOrder.ID CLng customerReader ID oneOrder.OrderDate CDate customerReader OrderDate oneOrder.OrderTotal CDec customerReader Total AllOrders.Items.Add oneOrder Loop This code accesses the records in the second set of results the SELECT statement for the OrderEntry table via the NextResult method call. 5. Run the program. On the Customer Management form select a customer from the list of customers and then click View Orders. When the View Orders form appears it includes content from both SELECT statements returned by the stored procedure. Summary This chapter discussed parameters which are data value objects that help ensure the accuracy and safety of the data being sent to and returned from external data sources. Parameterized queries use special SQL statements that include placeholders for each parameter. Each SqlParameter instance defines the name of the parameter its data type and its value. Parameters work with either standard SQL commands or with stored procedures. When using them with stored procedures you can create both input and output stored procedures supporting two-way communications with these custom database functions. Chapter 10 Adding Standards to Queries 167 Chapter 10 Quick Reference To Do This Create a parameterized query for SQL Server Create a SQL query string that includes -prefixed placeholders. Create a SqlCommand instance. Assign the SQL query to the SqlCommand object s CommandText property. Create SqlParameter objects one for each placeholder in the query and add them to the command object s Parameters collection. Set the SqlCommand.Connection property. Call one of the command object s Execute methods. Create a parameterized query for an OLE DB data source Create a SQL query string that includes question marks for placeholders. .