7.17. Using ADO.NET 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 ADO.NET 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
Component0717.cs, add two controls to its
design surface:
Drop a
SqlDataAdapteronto 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 OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry FROM OrdersAfter the wizard completes, rename the
SqlDataAdaptercontrol toda.A
SqlConnectioncontrol is automatically added to the design surface when theSqlDataAdapterwizard is completed; rename it toconn.
The sample code for the component exposes one property and one method:
MyDataTableA read-only property that returns a
DataTablefilled using theSqlDataAdaptercontrol.Update( )This method takes a
DataTableobject argument that uses theSqlDataAdaptercontrol to update changes to theDataTable(retrieved using theMyDataTable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access