Home > Articles

Working with DataSets

  • Print
  • + Share This
This chapter is from the book

Answers for Day 3

Exercise Answer

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

  ' 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.

  • + Share This
  • 🔖 Save To Your Account