Using ADO.NET Design-Time Features in Classes Without a GUI

[ Team LiB ] Recipe Using Design-Time Features in Classes Without a GUI Problem The design-time environment provides controls and wizards to facilitate creation of and management of properties of objects. | Team LiB Recipe Using Design-Time Features in Classes Without a GUI Problem The design-time environment provides controls and wizards to facilitate creation of and management of properties of objects. You want to use that design-time functionality when creating classes that do not have a GUI. Solution Create a component and use its design-time functionality. The solution contains two parts the component and the test container for the component. To create the component add two controls to its design surface Drop a SqlDataAdapter onto the design surface and use the Data Adapter Configuration Wizard to connect to the Northwind sample database on the local SQL Server. Accept all wizard defaults supply the following SQL statement when prompted to generate the SQL statements SELECT OrderlD CustomerlD EmployeeID OrderDate RequiredDate ShippedDate ShipVia Freight ShipName ShipAddress ShipCity ShipRegion ShipPostalCode ShipCountry FROM Orders After the wizard completes rename the SqlDataAdapter control to da. A SqlConnection control is automatically added to the design surface when the SqlDataAdapter wizard is completed rename it to conn. The sample code for the component exposes one property and one method MyDataTable A read-only property that returns a DataTable filled using the SqlDataAdapter control. Update This method takes a DataTable object argument that uses the SqlDataAdapter control to update changes to the DataTable retrieved using the MyDataTable property of the component back to the database. The C code for the component is shown in Example 7-33. Example 7-33. File Namespaces variables and constants using System using using . . . public DataTable MyDataTable get Fill a table using the DataAdapter control. DataTable dt new DataTable dt return dt public void Update DataTable dt Update the table back to the data source. dt The test container sample code .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
Đã 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.