Recently, I was tasked to write an ASP.NET application that allowed a user to make corrections to his data, validate the change on a specific row and save the change back to the Oracle database. Also, if a user clicked the refresh hyperlink, he could reset the values for that specific row back to the original values. The application would also allow the user to search for a specific domain value via a popup window and save the value back to the designated field of the specified row. This application had to dynamically identify the table that needed correcting. This table was identified by getting the scheme and table name from a configuration table. Now, for this version, release 1, the columns were static and easily identified.
For release 2 of this same application, the column names were generated dynamically and were no longer static. Since each department in the company had different naming conventions for its table definition, we could not assume that we knew what the column names would be. So now, we had to identify the table and the columns dynamically. I also used the DataGrid in this project so that the customer could navigate throughout the entire recordset via the DataGrid’s paging capability and make changes to any row within the Table object. Furthermore, the controls inside of the DataGrid would dynamically show only those columns that were used by a specific system. For example if your key values consisted of three columns then only those three columns would be rendered to the screen, and if the key column consisted of only one column then only that one column would be shown. This was a very dynamic DataGrid that changed when the configuration table changed.
The solution was to use a DataSet to save and manipulate the data. I was not a fan of the DataSet and I felt that it was often overkill. I mean really guys, how many developers would find a need to manipulate more than one table within a DataSet? But, after working on this project, I am more of a fan now. Well, I am really a fan of the DataTable and the DataRow not the DataSet. But, since I cannot populate a DataTable without the DataSet, I am now a DataSet fan.
What was most exciting about the DataTable was how easy it was to identify a row that needed updating. To identify the row, the DataRowCollection provides a method called Find(). This method acquires a specific row identified by the array of primary key values passed to it.