FoundRow = MyDataTable.Rows.Find(PrimaryKeyValues);
FoundRow["COLUMN1"] = "NEWVALUE1";
FoundRow["COLUMN2"] = "NEWVALUE2";
Once you identify the row in the DataSet using the values from the DataGrid, all you need to do then is assign your new value to the row object as illustrated above.
Now, remember that there was also a requirement to reset the row back to its original value when the refresh link was clicked. Can you imagine what it would have taken to implement this capability in classical ASP? The entire project would have taken three times as long. First of all, I would have needed a temporary working table available when making changes to the recordset so that I could keep track of the changes made. I also needed a reference back to the row’s original value. All of this just to be able to reset the row back to its original values.
It should also be known that temporary tables in Oracle are different than in SQL Server. In SQL Server, you can create a temp table dynamically, on the fly, but in Oracle you have to create the definition in advance. This is a weakness in Oracle. Although I would have a unique instance for each user in Oracle, the problem with Oracle is that my user’s table structure would change depending on the department that was using this application. For example, Department A may not carry the “SSN” column but Department B might carry the “SSN” column. I needed the ability to dynamically create my temporary tables based on the columns defined in the configuration table. Also, I needed the ability for 1 to n number of users to be able to make changes to their data. This meant that for each user session, there would have to be a temporary working table available to track changes.
The DataRow object just made this way too easy. I did not have to do anything to fulfill these requirements using ASP.NET!
The DataRow object automatically keeps track of the original value and the current value! I couldn’t ask for more! See the code below.
//Reset column back to its original value
FoundRow["COLUMN1"] = FoundRow["COLUMN1",DataRowVersion.Original];
//Set column back to its modified value
FoundRow["COLUMN1"] = Row["COLUMN1",DataRowVersion.Current]
The above code is all that is needed. The DataRow automatically saves this information. That is all there is to it! This saved me hours of coding! This feature also made it simple for me to create an audit log. The audit log tracked all changes made to the row. This log needed to log the original value and the new value. With the above code, this was a simple process. This capability is already built into the DataRow object.
I wanted to bring to light how easy it was to implement the requirements of this project by using the DataSet, the DataTable and the DataRow. I hope this article was enlightening. Happy Coding!