DekGenius.com
[ Team LiB ] Previous Section Next Section

22.2 Properties Reference

CaseSensitive

Boolean caseSensitive = DataSet.CaseSensitive;
DataSet.CaseSensitive = caseSensitive;

Gets or sets a value that indicates whether string comparisons within the DataTable objects in the DataSet are treated as case-sensitive.

Example

The following instructs the DataSet to treat string comparisons as case-sensitive:

DataSet ds = new DataSet();
ds.CaseSensitive = true;

Notes

The CaseSensitive property affects sorting, searching, and filtering within the DataSet.

The DataTable also has a CaseSensitive property. If the CaseSensitive property for a DataTable belonging to a DataSet has not been explicitly set, its value defaults to the value of the CaseSensitive property of the DataSet.

The default value of the CaseSenstive property is false.

DataSetName

String dataSetName = DataSet.DataSetName;
DataSet.DataSetName = dataSetName;

Gets or sets the name of the DataSet.

Example

The following example sets the name of a newly created DataSet:

DataSet ds = new DataSet();
ds.DataSetName = "MyDataSet";

Notes

The value for the DataSetName property can also be set using the DataSet constructor as shown in the following sample:

DataSet ds = new DataSet("MyDataSet");

If the contents of the DataSet are output as XML, the DataSetName is used as the name of the root node in the XML document.

The DataSetName property defaults to NewDataSet if it isn't explicitly specified.

DefaultViewManager

DataViewManager dvm = DataSet.DefaultViewManager;

Gets a reference to the default DataViewManager for the DataSet.

Example

The following example uses the DataViewManager property to access and set the property, which indicates that the default sort order should be used for all DataViews created from the DataViewManager:

DataViewManager dvm = ds.DefaultViewManager;
foreach(DataViewSetting dvs in dvm.DataViewSettings)
{
    dvs.ApplyDefaultSort = true;
}

Notes

The DataViewManager provides a convenient way to manage the default DataView settings for all tables in the DataSet and allows you to create new DataView objects for tables in the DataSet.

The DataViewManager contains a collection of DataViewSetting objects that can set the default values for the ApplyDefaultSort, Sort, RowFilter, and RowStateFilter properties for views on tables in the DataSet.

The public properties the DataViewManager class are described in Table 22-5.

Table 22-5. DataViewManager public properties

Property

Description

DataSet

Gets or sets the name of the DataSet to use with the DataViewManager.

DataViewSettings

Gets the DataViewSettingCollection for each DataTable in the DataSet.

The public methods of the DataViewManager class are described in Table 22-6.

Table 22-6. DataViewManager public methods

Method

Description

CreateDataView(  )

Creates a DataView for the specified DataTable.

EnforceConstraints

Boolean enforceConstraints = DataSet.EnforceConstraints;
DataSet.EnforceConstraints = enforceConstraints;

Gets or sets a value indicating whether the constraints defined for the tables in the DataSet are enforced when data is edited or added. There are two types of constraints in ADO.NET: foreign key and unique. Foreign key constraints define how updates and deletes are propagated to related tables. Unique constraints ensure that the data in a column or columns is unique among all the rows in the table.

Example

The following example turns off constraint enforcement for the DataSet:

DataSet ds = new DataSet();
ds.EnforceConstraints = false;

Notes

If the EnforceConstraints property is true and a Constraint within the DataSet is violated, a ConstraintException error is raised.

The EnforceConstraint property can be set to false prior to filling the DataSet and set back to true after the data is loaded. This permits the data to be loaded in an arbitrary order.

The default value of the EnforceConstraints property is true.

HasErrors

Boolean hasErrors = DataSet.HasErrors;

Gets a value indicating whether there are errors in any of the rows in any of the tables in the DataSet.

Example

The following example shows how to use the HasErrors property to determine the success of the reconciliation of a modified DataSet with the data source:

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();

// ... define the DataAdapter

// fill the DataSet
da.Fill(ds);

// ... modify the data in the DataSet

da.Update(ds);
if (ds.HasErrors)
{
    // ... handle the errors
}

Notes

If the DataAdapter ContinueUpdateOnError property is true when the Update( ) method of the DataAdapter is called, and one or more rows fail the update attempt, the RowError property for the failed rows is set, and the operation continues with the next record. The HasErrors property can be called after the update attempt to determine whether any of the row update attempts has failed. To optimize performance, check this property before checking the HasErrors property of the DataTable and DataRow objects.

The DataTable and DataRow classes also expose a HasErrors property.

Locale

CultureInfo locale = DataSet.Locale;
DataSet.Locale = locale;

Gets or sets the locale information that is the basis of string comparisons in tables.

Example

The following code demonstrates how to set the Locale property of the DataSet to Spanish:

DataSet ds = new DataSet();
ds.Locale = new CultureInfo("es");

Notes

The Locale property determines how sorting, comparisons, and filtering will be performed within the DataSet. The CultureInfo class exists in the System.Globalization namespace.

If the Locale property for a DataTable contained in the DataSet isn't explicitly set, it defaults to the Locale value for the DataSet it belongs to.

The default for the Locale property is the current system CultureInfo.

Namespace

String namespace = DataSet.Namespace;
DataSet.Namespace = namespace;

Gets or sets the namespace for the XML representation of the data stored in the DataSet.

Example

The following example sets the Namespace property of the DataSet:

DataSet ds = new DataSet();
ds.Namespace = "AdoDotNetIan";

Note

The Namespace property scopes the XML attributes and elements when reading and writing the DataSet using the ReadXml( ), WriteXml( ), ReadXmlSchema( ), and WriteXmlSchema( ) methods.

Prefix

String prefix = DataSet.Prefix;
DataSet.Prefix = prefix;

Gets or sets an XML prefix that aliases the namespace of the DataSet.

Example

The following example sets the NameSpace and Prefix properties of the DataSet and uses them to scope the XML loaded into the DataSet using the ReadXml method:

DataSet ds = new DataSet();

ds.Namespace = "AdoDotNetIan";
ds.Prefix = "adni";

// read the XML from the file into the DataSet
ds.ReadXml("myXmlFile.xml");

Note

The Prefix is used within the XML document to identify attributes and elements that belong to the namespace of the DataSet object as defined by the Namespace property.

    [ Team LiB ] Previous Section Next Section