Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

What data access programming model does the DataSet enable?

A1:

The DataSet allows you to build applications that work with data that is entirely disconnected from its data source. It does this by storing the data in an in-memory cache represented as XML and that is serializable for transport across tiers in your application.

2:

Can a single DataSet be populated using both a data adapter and explicit code?

A2:

Yes. Different tables in a DataSet can be populated in different ways. For example, one table could be populated from a data adapter connected to SQL Server, another to a data adapter connected to Oracle, and a third through explicit code that creates new rows manually. This feature is what allows the DataSet to store heterogeneous data.

3:

How do you combine the contents of two DataSet objects?

A3:

You can combine the data in multiple DataSet objects using the Merge method of the DataSet object that will act as the final repository. Keep in mind that errors might result if the schema of the tables differs or if constraints are violated, and that changes in the original DataSet will be overridden by default. If the two DataSet objects contain different tables, they can simply be merged into a single DataSet that contains both tables.

4:

What is the primary use for the DataViewManager ?

A4:

The DataViewManager is used to manage the view settings for the collection of tables in a DataSet . Basically, it exposes the sorting and filtering properties of the DataView objects associated with the tables in the DataSet . The DataViewManager can then be associated with a control's DataSource property to enable custom views during data binding.

Exercise

Q1:

To try out the concepts discussed today, write a method that retrieves the Titles , Categories , and Publishers information from the ComputeBooks database using the usp_GetTitlesLookups stored procedure. After retrieving the data into a DataSet , create a DataViewManager that shows only the titles with a price greater than $25 and sorts the publishers by PubCode .

A1:

One possible solution to the exercise is as follows :

 Public Function GetTitlesLookups(ByVal connect As String) As DataViewManager   Dim con As New SqlConnection(connect)   Dim da As New SqlDataAdapter("usp_GetTitlesLookups", con)   Dim dsTitlesLookups As New DataSet("TitlesLookups")   ' Fill the DataSet   da.Fill(dsTitlesLookups)     ' Create the data view manager and set the properties     Dim dvm As New DataViewManager(dsTitlesLookups)     dvm.DataViewSettings("Table").RowFilter = "Price > 25"     dvm.DataViewSettings("Table2").Sort = "PubCode ASC"     Return dvm End Function 

In this method, the dsTitlesLookups DataSet is populated by the SqlDataAdapter da using the Fill method. The DataSet will contain three tables (Table, Table1, and Table2, which are the defaults) with the Titles , Categories , and Publishers data. The DataViewManager can then be created and its individual DataViewSettings accessed through the collection.

for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net