The Power of the DataSet's DataTable and DataRow Objects
page 2 of 2
by King & Keith Wells
Average Rating: 
Views (Total / Last 10 Days): 16350/ 29

The DataSet In Action


DataRow FoundRow;
object[] PrimaryKeyValues;

PrimaryKeyValues[0]= "Keith";
PrimaryKeyValues[1]= "Wells";
PrimaryKeyValues[2]= "Louisiana";
PrimaryKeyValues[3]= "GROUP1";

FoundRow = MyDataTable.Rows.Find(PrimaryKeyValues);
if (FoundRow!=null)
      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!

View Entire Article

User Comments

Title: save the value from dynamic table   
Name: sanjay
Date: 2007-03-03 12:46:32 AM
i am create dynamic table in page and i entered value in run time and save those value from table when i click to save button then page postback and all value refresh...then how i save those value in database...
Name: alex
Date: 2006-04-07 4:55:28 AM
I may just start being a fan of dataset if mi am helped thnanks
Title: Identify the Dynamic Table Objects   
Name: Prabakar
Date: 2005-06-26 10:49:00 PM

I'm using a Dynamic Table to edit a database table

Which shows all the records in it...

and I can retrive the data from database but I don't know

how to find the datas entered in the Dynamic Objects...

I have three Text box in my Dynamic Table I want know their ID or name Property in the code behind
Title: Web Developer   
Name: Peer Sajad
Date: 2005-03-15 11:13:12 PM
I was just wandering how to do it, thankyou very much!
Name: Bill Phillips
Date: 2005-01-30 11:46:16 AM
I'm learning more and more about .Net. Your insight helps to further understand how useful the Dataset and Datatable are in developing software.
I see already the time I save by not having to create all my reports(web) using .asp pages.
I've been in this business a long time and glad to see you guys are doing ok.

Thank you for your input


Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2022  |  Page Processed at 2022-10-01 10:05:12 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search