1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
|
<docs>
<class>
<summary>
Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated MySQL database. This class cannot be inherited.
</summary>
<remarks>
<para>
The <see cref="MySqlDataAdapter"/> does not automatically generate the SQL statements required to
reconcile changes made to a <see cref="System.Data.DataSet">DataSet</see> with the associated instance of MySQL.
However, you can create a <B>MySqlCommandBuilder</B> object to automatically generate SQL statements for
single-table updates if you set the <see cref="MySqlDataAdapter.SelectCommand">SelectCommand</see> property
of the <B>MySqlDataAdapter</B>. Then, any additional SQL statements that you do not set are generated by the
<B>MySqlCommandBuilder</B>.
</para>
<para>
The <B>MySqlCommandBuilder</B> registers itself as a listener for <see cref="MySqlDataAdapter.OnRowUpdating">RowUpdating</see>
events whenever you set the <see cref="DataAdapter"/> property. You can only associate one
<B>MySqlDataAdapter</B> or <B>MySqlCommandBuilder</B> object with each other at one time.
</para>
<para>
To generate INSERT, UPDATE, or DELETE statements, the <B>MySqlCommandBuilder</B> uses the
<B>SelectCommand</B> property to retrieve a required set of metadata automatically. If you change
the <B>SelectCommand</B> after the metadata has is retrieved (for example, after the first update), you
should call the <see cref="RefreshSchema"/> method to update the metadata.
</para>
<para>
The <B>SelectCommand</B> must also return at least one primary key or unique
column. If none are present, an <I>InvalidOperation</I> exception is generated,
and the commands are not generated.
</para>
<para>
The <B>MySqlCommandBuilder</B> also uses the <see cref="MySqlCommand.Connection">Connection</see>,
<see cref="MySqlCommand.CommandTimeout">CommandTimeout</see>, and <see cref="MySqlCommand.Transaction">Transaction</see>
properties referenced by the <B>SelectCommand</B>. The user should call
<B>RefreshSchema</B> if any of these properties are modified, or if the
<B>SelectCommand</B> itself is replaced. Otherwise the <see cref="MySqlDataAdapter.InsertCommand">InsertCommand</see>,
<see cref="MySqlDataAdapter.UpdateCommand">UpdateCommand</see>, and
<see cref="MySqlDataAdapter.DeleteCommand">DeleteCommand</see> properties retain
their previous values.
</para>
<para>
If you call <i>Dispose</i>, the <B>MySqlCommandBuilder</B> is disassociated
from the <B>MySqlDataAdapter</B>, and the generated commands are no longer used.
</para>
<note>
Caution must be used when using MySqlCOmmandBuilder on MySql 4.0 systems. With MySql 4.0,
database/schema information is not provided to the connector for a query. This means that
a query that pulls columns from two identically named tables in two or more different databases
will not cause an exception to be thrown but will not work correctly. Even more dangerous
is the situation where your select statement references database X but is executed in
database Y and both databases have tables with similar layouts. This situation can cause
unwanted changes or deletes.
This note does not apply to MySQL versions 4.1 and later.
</note>
</remarks>
<example>
The following example uses the <see cref="MySqlCommand"/>, along
<see cref="MySqlDataAdapter"/> and <see cref="MySqlConnection"/>, to
select rows from a data source. The example is passed an initialized
<see cref="System.Data.DataSet"/>, a connection string, a
query string that is a SQL SELECT statement, and a string that is the
name of the database table. The example then creates a <B>MySqlCommandBuilder</B>.
<code lang="vbnet">
Public Shared Function SelectRows(myConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New MySqlConnection(myConnection)
Dim myDataAdapter As New MySqlDataAdapter()
myDataAdapter.SelectCommand = New MySqlCommand(mySelectQuery, myConn)
Dim cb As SqlCommandBuilder = New MySqlCommandBuilder(myDataAdapter)
myConn.Open()
Dim ds As DataSet = New DataSet
myDataAdapter.Fill(ds, myTableName)
' Code to modify data in DataSet here
' Without the MySqlCommandBuilder this line would fail.
myDataAdapter.Update(ds, myTableName)
myConn.Close()
End Function 'SelectRows
</code>
<code lang="C#">
public static DataSet SelectRows(string myConnection, string mySelectQuery, string myTableName)
{
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
myDataAdapter.SelectCommand = new MySqlCommand(mySelectQuery, myConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
myConn.Open();
DataSet ds = new DataSet();
myDataAdapter.Fill(ds, myTableName);
//code to modify data in DataSet here
//Without the MySqlCommandBuilder this line would fail
myDataAdapter.Update(ds, myTableName);
myConn.Close();
return ds;
}
</code>
</example>
</class>
<Ctor>
<summary>
Initializes a new instance of the <see cref="MySqlCommandBuilder"/> class.
</summary>
</Ctor>
<Ctor2>
<summary>
Initializes a new instance of the <see cref="MySqlCommandBuilder"/> class
with the associated <see cref="MySqlDataAdapter"/> object.
</summary>
<param name="adapter">
The <see cref="MySqlDataAdapter"/> to use.
</param>
<remarks>
<para>
The <see cref="MySqlCommandBuilder"/> registers itself as a listener for
<see cref="MySqlDataAdapter.RowUpdating"/> events that are generated by the
<see cref="MySqlDataAdapter"/> specified in this property.
</para>
<para>
When you create a new instance <B>MySqlCommandBuilder</B>, any existing
<B>MySqlCommandBuilder</B> associated with this <B>MySqlDataAdapter</B>
is released.
</para>
</remarks>
</Ctor2>
<DataAdapter>
<summary>
Gets or sets a <see cref="MySqlDataAdapter"/> object for which SQL statements are automatically generated.
</summary>
<value>
A <see cref="MySqlDataAdapter"/> object.
</value>
<remarks>
<para>
The <see cref="MySqlCommandBuilder"/> registers itself as a listener for
<see cref="MySqlDataAdapter.RowUpdating"/> events that are generated by the
<see cref="MySqlDataAdapter"/> specified in this property.
</para>
<para>
When you create a new instance <B>MySqlCommandBuilder</B>, any existing
<B>MySqlCommandBuilder</B> associated with this <B>MySqlDataAdapter</B>
is released.
</para>
</remarks>
</DataAdapter>
<QuotePrefix>
<summary>
Gets or sets the beginning character or characters to use when specifying MySQL
database objects (for example, tables or columns) whose names contain
characters such as spaces or reserved tokens.
</summary>
<value>
The beginning character or characters to use. The default value is `.
</value>
<remarks>
Database objects in MySQL can contain special characters such as spaces that would
make normal SQL strings impossible to correctly parse. Use of the <b>QuotePrefix</b>
and the <see cref="QuoteSuffix"/> properties allows the <see cref="MySqlCommandBuilder"/>
to build SQL commands that handle this situation.
</remarks>
</QuotePrefix>
<QuoteSuffix>
<summary>
Gets or sets the beginning character or characters to use when specifying MySQL
database objects (for example, tables or columns) whose names contain
characters such as spaces or reserved tokens.
</summary>
<value>
The beginning character or characters to use. The default value is `.
</value>
<remarks>
Database objects in MySQL can contain special characters such as spaces that would
make normal SQL strings impossible to correctly parse. Use of the <see cref="QuotePrefix"/>
and the <b>QuoteSuffix</b> properties allows the <see cref="MySqlCommandBuilder"/>
to build SQL commands that handle this situation.
</remarks>
</QuoteSuffix>
<DeriveParameters>
<summary>
</summary>
<remarks>
</remarks>
</DeriveParameters>
<GetDeleteCommand>
<summary>
Gets the automatically generated <see cref="MySqlCommand"/> object
required to perform deletions on the database.
</summary>
<returns>
The <see cref="MySqlCommand"/> object generated to handle delete operations.
</returns>
<remarks>
<para>
An application can use the <B>GetDeleteCommand</B> method for informational
or troubleshooting purposes because it returns the <see cref="MySqlCommand"/>
object to be executed.
</para>
<para>
You can also use <B>GetDeleteCommand</B> as the basis of a modified command.
For example, you might call <B>GetDeleteCommand</B> and modify the
<see cref="MySqlCommand.CommandTimeout"/> value, and then explicitly set that on the
<see cref="MySqlDataAdapter"/>.
</para>
<para>
After the SQL statement is first generated, the application must explicitly
call <see cref="RefreshSchema"/> if it changes the statement in any way.
Otherwise, the <B>GetDeleteCommand</B> will be still be using information
from the previous statement, which might not be correct. The SQL statements
are first generated either when the application calls
<see cref="System.Data.Common.DataAdapter.Update"/> or <B>GetDeleteCommand</B>.
</para>
</remarks>
</GetDeleteCommand>
<GetInsertCommand>
<summary>
Gets the automatically generated <see cref="MySqlCommand"/> object
required to perform insertions on the database.
</summary>
<returns>
The <see cref="MySqlCommand"/> object generated to handle insert operations.
</returns>
<remarks>
<para>
An application can use the <B>GetInsertCommand</B> method for informational
or troubleshooting purposes because it returns the <see cref="MySqlCommand"/>
object to be executed.
</para>
<para>
You can also use the <B>GetInsertCommand</B> as the basis of a modified command.
For example, you might call <B>GetInsertCommand</B> and modify the
<see cref="MySqlCommand.CommandTimeout"/> value, and then explicitly set that on the
<see cref="MySqlDataAdapter"/>.
</para>
<para>
After the SQL statement is first generated, the application must explicitly
call <see cref="RefreshSchema"/> if it changes the statement in any way.
Otherwise, the <B>GetInsertCommand</B> will be still be using information
from the previous statement, which might not be correct. The SQL statements
are first generated either when the application calls
<see cref="System.Data.Common.DataAdapter.Update"/> or <B>GetInsertCommand</B>.
</para>
</remarks>
</GetInsertCommand>
<GetUpdateCommand>
<summary>
Gets the automatically generated <see cref="MySqlCommand"/> object
required to perform updates on the database.
</summary>
<returns>
The <see cref="MySqlCommand"/> object generated to handle update operations.
</returns>
<remarks>
<para>
An application can use the <B>GetUpdateCommand</B> method for informational
or troubleshooting purposes because it returns the <see cref="MySqlCommand"/>
object to be executed.
</para>
<para>
You can also use <B>GetUpdateCommand</B> as the basis of a modified command.
For example, you might call <B>GetUpdateCommand</B> and modify the
<see cref="MySqlCommand.CommandTimeout"/> value, and then explicitly set that on the
<see cref="MySqlDataAdapter"/>.
</para>
<para>
After the SQL statement is first generated, the application must explicitly
call <see cref="RefreshSchema"/> if it changes the statement in any way.
Otherwise, the <B>GetUpdateCommand</B> will be still be using information
from the previous statement, which might not be correct. The SQL statements
are first generated either when the application calls
<see cref="System.Data.Common.DataAdapter.Update"/> or <B>GetUpdateCommand</B>.
</para>
</remarks>
</GetUpdateCommand>
<RefreshSchema>
<summary>
Refreshes the database schema information used to generate INSERT, UPDATE, or
DELETE statements.
</summary>
<remarks>
<para>
An application should call <B>RefreshSchema</B> whenever the SELECT statement
associated with the <see cref="MySqlCommandBuilder"/> changes.
</para>
<para>
An application should call <B>RefreshSchema</B> whenever the
<see cref="MySqlDataAdapter.SelectCommand"/> value of the <see cref="MySqlDataAdapter"/> changes.
</para>
</remarks>
</RefreshSchema>
</docs>
|