Webocreation

Monday, October 11, 2010

Adding Custom Information


Adding Custom Information

The DataSet contains a PropertyCollection that is exposed through the ExtendedProperties property. This collection allows a user to add custom information to the DataSet such as the date and time when the DataSet should be refreshed. The following example sets an extended property indicating that the DataSet should be refreshed in 20 minutes:
ds.ExtendedProperties.Add("RefreshDateTime",
    DateTime.Now.AddMinutes(20).ToString());
The following code can then check that value to see if the DataSet needs to be refreshed:
if(DateTime.Now>Convert.ToDateTime(
    ds.ExtendedProperties["RefreshDateTime"].ToString( ) ))
{
    // ... code to refresh the DataSet
}
Extended properties must be of type String, or else they will not persist when the DataSet is written as XML.
The DataTable, DataColumn, DataRelation, and Constraint objects also have a similar collection of extended properties.

Cloning the Schema

The Clone( ) method creates a new DataSet with the same structure, including table schemas and relations, as the original but containing none of the data in the original DataSet. The following example uses the Clone( ) method to create a new DataSet:
// create a DataSet object variable to receive the clone
DataSet cloneDs;
cloneDs = ds.Clone();

Cloning the Schema

The Clone( ) method creates a new DataSet with the same structure, including table schemas and relations, as the original but containing none of the data in the original DataSet. The following example uses the Clone( ) method to create a new DataSet:
// create a DataSet object variable to receive the clone
DataSet cloneDs;
cloneDs = ds.Clone();

Copying the DataSet

The Copy( ) method of the DataSet creates a new DataSet with the same structure, including tables schemas and relations, and data as the original DataSet. The following example uses the Copy( ) method to create a new DataSet:
// create a DataSet object variable to receive the copy
DataSet copyDs;
copyDs = ds.Copy();

Removing All Data

The Clear( ) method removes all rows from all tables in the DataSet:
ds.Clear();

Removing All Data

The Clear( ) method removes all rows from all tables in the DataSet:
ds.Clear();

Committing and Discarding Changes

When a DataRow is modified, ADO.NET marks the row as having a changes and sets the RowState of the DataRow to Added, Modified, or Deleted, as appropriate. ADO.NET also maintains version information by storing both Original and Current versions of each row. Together, this information allows ADO.NET or an application to identify the rows and columns that have been changed.

No comments:

Post a Comment