22.2 Properties Reference


 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.


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

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


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 .


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

Gets or sets the name of the DataSet .


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

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


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.


 DataViewManager   dvm   = DataSet.DefaultViewManager; 

Gets a reference to the default DataViewManager for the DataSet .


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; } 


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




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


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



 CreateDataView(  ) 

Creates a DataView for the specified DataTable .


 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.


The following example turns off constraint enforcement for the DataSet :

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


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 .


 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 .


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 } 


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.


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

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


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

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


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 .


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

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


The following example sets the Namespace property of the DataSet :

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


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


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

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


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"); 


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.

ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net