23.2 Properties Reference
Boolean caseSensitive = DataTable.CaseSensitive;
DataTable.CaseSensitive = caseSensitive;
|
|
Gets or sets a value indicating whether string comparisons within the
DataTable are treated as case-sensitive.
Example
The following example instructs the DataTable to
treat string comparisons as case-sensitive:
DataTable dt = new DataTable();
dt.CaseSensitive = true;
Notes
The CaseSensitive property affects sorting,
searching, and filtering within the DataTable.
If the value of the CaseSensitive property
isn't explicitly set, it defaults to the value of
the CaseSensitive property of the
DataSet the table belongs to.
DataSet ds = DataTable.DataSet;
|
|
Gets a reference to the DataSet the
DataTable belongs to.
Example
The following example shows how to retrieve a reference to the
DataSet that the DataTable
belongs to:
DataTable dt = new DataTable();
// ... code to define the DataTable dt and add it to the DataSet
DataSet ds = dt.DataSet;
Note
This property returns a null reference if the
DataTable doesn't belong to a
DataSet.
DataView dv = DataTable.DefaultView;
|
|
Gets the default DataView that is associated with
the DataTable.
Example
The following example gets a reference to the default
DataView for the DataTable and
binds a DataGrid to that view:
DataTable dt = new DataTable();
// ... code to define the DataTable schema and populate it with data.
// returns the default DataView for the table.
DataView defaultView = dt.DefaultView;
// the next two statements both bind the DataGrid to
// the same default DataView
dataGrid.DataSource = defaultView ;
dataGrid.DataSource = dt; // DefaultView is implied
Note
If a control is bound to the DataTable, the
control actually binds to the DataView returned by
the DefaultView property.
String displayExpression = DataTable.DisplayExpression;
DataTable.DisplayExpression = displayExpression;
|
|
Gets or sets the expression that represents the table in the user
interface.
Example
The following example sets the DisplayExpression
property of the DataTable:
DataTable dt = new DataTable();
dt.DisplayExpression = "MyDataTable";
Boolean hasErrors = DataTable.HasErrors;
|
|
Gets a value that indicates whether there are errors in any of the
rows in the DataTable.
Example
The following example shows how to use the
HasErrors property to determine whether there are
errors in the DataTable after the reconciliation
of the modified DataTable with the data source:
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
// ... define the DataAdapter
// fill the DataTable
da.Fill(dt);
// ... modify the data in the DataTable
da.Update(dt);
if (dt.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. The HasErrors property can
be called after the update attempt to determine whether any row
update attempt has failed. To optimize performance, check the
DataTable HasErrors property
before checking the HasErrors property of the
DataRow objects.
The DataSet and DataRow classes
also expose a HasErrors property.
CultureInfo locale = DataTable.Locale;
DataTable.Locale = locale;
|
|
Gets or sets locale information that is used to compare strings
stored in the DataTable.
Example
The following code demonstrates how to set the
Locale property of the
DataTable to Spanish:
DataTable ds = new DataTable();
dt.Locale = new CultureInfo("es");
Notes
The Locale property for the
DataTable defaults to the
Locale value of the DataSet
that contains the table. If the DataTable
doesn't belong to a DataSet, the
Locale property defaults to the current value of
the system CultureInfo.
The Locale property determines how sorting,
comparisons, and filtering are performed within the
DataTable.
Int32 minimumCapacity = DataTable.MinimumCapacity;
DataTable.MinimumCapacity = minimumCapacity;
|
|
Gets or sets the initial starting size of the
DataTable in rows.
Example
The following example shows how to set the
MinimumCapacity of the
DataTable:
DataTable dt = new DataTable();
dt.MinimumCapacity = 1000;
Notes
Setting this property can optimize performance by allocating an
appropriate amount of resources to the table prior to retrieving
data. If this value is set below the number of rows in the table,
ADO.NET automatically requests additional memory.
The default value of the MinimumCapacity property
is 50 rows.
String namespace = DataTable.NameSpace;
DataTable.NameSpace = namespace;
|
|
Gets or sets the namespace for the XML representation of the data
stored in the DataTable.
Example
The following example sets the Namespace property
of the DataTable:
DataTable dt = new DataTable();
dt.Namespace = "AdoDotNetIan";
Note
The Namespace property scopes the XML attributes
and elements when reading and writing the
DataTable using the ReadXml( ),
WriteXml( ), ReadXmlSchema( ),
and WriteXmlSchema( ) methods of the
DataSet the table belongs to.
String prefix = DataTable.Prefix;
DataTable.Prefix = prefix;
|
|
Gets or sets the XML prefix that aliases the namespace of the
DataTable.
Example
The following example sets the Prefix property of
the DataTable:
DataTable dt = new DataTable();
dt.Prefix = "adni";
Note
The Prefix is used within the XML document to
identify attributes and elements that belong to the namespace of the
DataTable object defined by the
Namespace property.
String tableName = DataTable.TableName;
DataTable.TableName = tableName;
|
|
Gets or sets the name of the DataTable.
Example
The following example sets the name of a newly created
DataTable:
DataTable dt = new DataTable();
dt.TableName = "MyTable";
Notes
The value for the TableName property can also be
set using the DataTable constructor as shown in
the following example:
DataTable dt = new
DataTable("MyDataTable");
If the contents of the DataSet containing the
table are output as XML, the TableName is used as
the element tag for each row in the DataTable.
By default, TableName property has no value. If
the value has not been set when the table is added to the
DataTableCollection of a
DataSet, the table name defaults to Table, Table1,
and so on.
|