Working with DataSets by Greg Osefo
As part of the explore program, myself as well as the other VB Explorers have been developing an application to deploy onto the Pocket PC. One of the necessary components of our application is to be able to store information that the user inputs as well as information tat is read off of the hard drive of the Pocket PC. Our group original plan was to deploy our application and have it use SQLCe in order to perform queries on our dataset. After looking at some of the memory issues that we might encounter in deployment as well as the fact that many Pocket PC owners may not have SQLCe, we decided to work directly with the dataset and scrap the whole SQLCe query aspect.
In order to eliminate the SQLCe queries we had to find a way to directly look into a specific datatable within the dataset and pull out the row or rows that met the specified search criteria. In order to search for a specific row or specific rows, you have to create a dataview from a datatable within a dataset and then call the Find or FindRows function on that dataview. The Find function takes in a specific value to search for within a dataview and returns the row index containing the desired value. The Find Rows function takes in an object array of search criteria and returns an array of DataRowView’s of the specific rows containing the search criteria. The FindRows function is especially important when removing rows within a strongly typed dataset, but I will get into that a little later. For the most part all of my SQL queries could be converted to a Find or FindRows function call; moreover, when ever I wanted to find the maximum or minimum value for any specific column in a datatable, all I had to do was sort the specific column is Ascending (ASC) or descending (DESC) order.
Adding rows to a dataset table was not very difficult because it has a built in function which allows you to input, as parameters, the values for the new row. Removing rows from a datatable was not as easy as adding because you have to pass in the specific DataRow which you want to remove instead of just the values of the row. Fortunately, each of our datatables had a primary key and so we were able to call FindRows with a primary key and that returned a DataRowView of the specific row. With the DataRowView you can call the .Row function which returns the DataRow being viewed. So overall we were able to convert all of the SQL queries to regular function calls on a dataset datatable.
main reference: www.msdn.com
(posted by Greg Osefo)