30.2 Properties Reference
DataAdapter dataAdapter = CommandBuilder.DataAdapter;
CommandBuilder.DataAdapter = dataAdapter;
|
|
Gets or sets the DataAdapter for which the SQL
statements are automatically generated.
Example
The following example sets the DataAdapter
property for a newly created CommandBuilder
object:
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, connString);
SqlCommandBuilder cb = new SqlCommandBuilder();
cb.DataAdapter = da;
Notes
The DataAdapter property can be set for the
CommandBuilder object in the constructor, as shown
in this example:
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, connString);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
When a new CommandBuilder is associated with a
DataAdapter, any commands from a previous
associated CommandBuilder object are released.
String quotePrefix = CommandBuilder.QuotePrefix;
CommandBuilder.QuotePrefix = quotePrefix;
|
|
Gets or sets the character or characters that are prefixed to column,
table, and other object names. Together with the
QuoteSuffix property, this permits characters such
as spaces to be used when naming objects. The default value is an
empty string.
Example
The following example sets the QuotePrefix and
QuoteSuffix property to allow a SQL Server table
containing spaces to be specified:
SqlCommandBuilder cb = new SqlCommandBuilder();
cb.QuotePrefix = "[";
cd.QuoteSuffix = "]";
When the update statements are generated by the
CommandBuilder, the SQL Server object names within
the updating logic statements are delimited by open and close square
brackets.
Notes
Although any valid character can be accommodated by setting the
QuotePrefix and QuoteSuffix
property, the values of QuotePrefix and
QuoteSuffix must be valid delimiters in the data
source server. The characters used in the object name must be valid
for naming objects in the data source server.
The QuotePrefix property can't be
changed after the DELETE, INSERT, or UPDATE command has been
generated. Attempting to do so raises an
InvalidOperationException exception.
String quoteSuffix = CommandBuilder.QuoteSuffix;
CommandBuilder.QuoteSuffix = quoteSuffix;
|
|
Gets or sets the character or characters that are appended to column,
table, and other object names. Together with the
QuotePrefix property, this permits characters such
as spaces to be used when naming objects. The default value is an
empty string.
Example
See the Example for the QuotePrefix in this
chapter.
Notes
Although any valid character can be accommodated by setting the
QuotePrefix and QuoteSuffix
property, the values of QuotePrefix and
QuoteSuffix must be valid delimiters in the data
source server. The characters used in the object name must be valid
for naming objects in the data source server.
The QuoteSuffix property can't be
changed after the DELETE, INSERT, or UPDATE command has been
generated. Attempting to do so raises an
InvalidOperationException exception.
|