[ Team LiB ] |
22.2 Properties Reference
Gets or sets a value that indicates whether string comparisons within the DataTable objects in the DataSet are treated as case-sensitive. ExampleThe following instructs the DataSet to treat string comparisons as case-sensitive: DataSet ds = new DataSet(); ds.CaseSensitive = true; NotesThe 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.
Gets or sets the name of the DataSet. ExampleThe following example sets the name of a newly created DataSet: DataSet ds = new DataSet(); ds.DataSetName = "MyDataSet"; NotesThe 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.
Gets a reference to the default DataViewManager for the DataSet. ExampleThe 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; } NotesThe 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.
The public methods of the DataViewManager class are described in Table 22-6.
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. ExampleThe following example turns off constraint enforcement for the DataSet: DataSet ds = new DataSet(); ds.EnforceConstraints = false; NotesIf 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.
Gets a value indicating whether there are errors in any of the rows in any of the tables in the DataSet. ExampleThe 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 } NotesIf 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.
Gets or sets the locale information that is the basis of string comparisons in tables. ExampleThe following code demonstrates how to set the Locale property of the DataSet to Spanish: DataSet ds = new DataSet(); ds.Locale = new CultureInfo("es"); NotesThe 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.
Gets or sets the namespace for the XML representation of the data stored in the DataSet. ExampleThe following example sets the Namespace property of the DataSet: DataSet ds = new DataSet(); ds.Namespace = "AdoDotNetIan"; NoteThe Namespace property scopes the XML attributes and elements when reading and writing the DataSet using the ReadXml( ), WriteXml( ), ReadXmlSchema( ), and WriteXmlSchema( ) methods.
Gets or sets an XML prefix that aliases the namespace of the DataSet. ExampleThe 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"); NoteThe 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 ] |