The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MySqlDataAdapter.xml 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <docs>
  2. <class>
  3. <summary>
  4. Represents a set of data commands and a database connection that are used to fill a dataset and update a MySQL database. This class cannot be inherited.
  5. </summary>
  6. <remarks>
  7. <para>
  8. The <B>MySQLDataAdapter</B>, serves as a bridge between a <see cref="System.Data.DataSet"/>
  9. and MySQL for retrieving and saving data. The <B>MySQLDataAdapter</B> provides this
  10. bridge by mapping <see cref="DbDataAdapter.Fill(DataSet)"/>, which changes the data in the
  11. <B>DataSet</B> to match the data in the data source, and <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/>,
  12. which changes the data in the data source to match the data in the <B>DataSet</B>,
  13. using the appropriate SQL statements against the data source.
  14. </para>
  15. <para>
  16. When the <B>MySQLDataAdapter</B> fills a <B>DataSet</B>, it will create the necessary
  17. tables and columns for the returned data if they do not already exist. However, primary
  18. key information will not be included in the implicitly created schema unless the
  19. <see cref="System.Data.MissingSchemaAction"/> property is set to <see cref="System.Data.MissingSchemaAction.AddWithKey"/>.
  20. You may also have the <B>MySQLDataAdapter</B> create the schema of the <B>DataSet</B>,
  21. including primary key information, before filling it with data using <see cref="System.Data.Common.DbDataAdapter.FillSchema(DataTable, SchemaType)"/>.
  22. </para>
  23. <para>
  24. <B>MySQLDataAdapter</B> is used in conjunction with <see cref="MySqlConnection"/>
  25. and <see cref="MySqlCommand"/> to increase performance when connecting to a MySQL database.
  26. </para>
  27. <para>
  28. The <B>MySQLDataAdapter</B> also includes the <see cref="MySqlDataAdapter.SelectCommand"/>,
  29. <see cref="MySqlDataAdapter.InsertCommand"/>, <see cref="MySqlDataAdapter.DeleteCommand"/>,
  30. <see cref="MySqlDataAdapter.UpdateCommand"/>, and <see cref="DataAdapter.TableMappings"/>
  31. properties to facilitate the loading and updating of data.
  32. </para>
  33. <para>
  34. When an instance of <B>MySQLDataAdapter</B> is created, the read/write properties
  35. are set to initial values. For a list of these values, see the <B>MySQLDataAdapter</B>
  36. constructor.
  37. </para>
  38. <note>
  39. Please be aware that the <see cref="DataColumn"/> class allows only
  40. Int16, Int32, and Int64 to have the AutoIncrement property set.
  41. If you plan to use autoincremement columns with MySQL, you should consider
  42. using signed integer columns.
  43. </note>
  44. </remarks>
  45. <example>
  46. The following example creates a <see cref="MySqlCommand"/> and a <see cref="MySqlConnection"/>.
  47. The <B>MySqlConnection</B> is opened and set as the <see cref="MySqlCommand.Connection"/> for the
  48. <B>MySqlCommand</B>. The example then calls <see cref="MySqlCommand.ExecuteNonQuery"/>, and closes
  49. the connection. To accomplish this, the <B>ExecuteNonQuery</B> is
  50. passed a connection string and a query string that is a SQL INSERT
  51. statement.
  52. <code lang="vbnet">
  53. Public Function SelectRows(dataSet As DataSet, connection As String, query As String) As DataSet
  54. Dim conn As New MySqlConnection(connection)
  55. Dim adapter As New MySqlDataAdapter()
  56. adapter.SelectCommand = new MySqlCommand(query, conn)
  57. adapter.Fill(dataset)
  58. Return dataset
  59. End Function
  60. </code>
  61. <code lang="C#">
  62. public DataSet SelectRows(DataSet dataset,string connection,string query)
  63. {
  64. MySqlConnection conn = new MySqlConnection(connection);
  65. MySqlDataAdapter adapter = new MySqlDataAdapter();
  66. adapter.SelectCommand = new MySqlCommand(query, conn);
  67. adapter.Fill(dataset);
  68. return dataset;
  69. }
  70. </code>
  71. </example>
  72. </class>
  73. <Ctor>
  74. <overloads></overloads>
  75. <summary>
  76. Initializes a new instance of the MySqlDataAdapter class.
  77. </summary>
  78. <remarks>
  79. <para>
  80. When an instance of <see cref="MySqlDataAdapter"/> is created,
  81. the following read/write properties are set to the following initial
  82. values.
  83. </para>
  84. <list type="table">
  85. <listheader>
  86. <term>Properties</term>
  87. <term>Initial Value</term>
  88. </listheader>
  89. <item>
  90. <term>
  91. <see cref="MissingMappingAction"/>
  92. </term>
  93. <term>
  94. <B>MissingMappingAction.Passthrough</B>
  95. </term>
  96. </item>
  97. <item>
  98. <term>
  99. <see cref="MissingSchemaAction"/>
  100. </term>
  101. <term>
  102. <B>MissingSchemaAction.Add</B>
  103. </term>
  104. </item>
  105. </list>
  106. <para>
  107. You can change the value of any of these properties through a separate call
  108. to the property.
  109. </para>
  110. </remarks>
  111. <example>
  112. The following example creates a <see cref="MySqlDataAdapter"/> and sets some of
  113. its properties.
  114. <code lang="vbnet">
  115. Public Sub CreateSqlDataAdapter()
  116. Dim conn As MySqlConnection = New MySqlConnection("Data Source=localhost;" &amp; _
  117. "database=test")
  118. Dim da As MySqlDataAdapter = New MySqlDataAdapter
  119. da.MissingSchemaAction = MissingSchemaAction.AddWithKey
  120. da.SelectCommand = New MySqlCommand("SELECT id, name FROM mytable", conn)
  121. da.InsertCommand = New MySqlCommand("INSERT INTO mytable (id, name) " &amp; _
  122. "VALUES (@id, @name)", conn)
  123. da.UpdateCommand = New MySqlCommand("UPDATE mytable SET id=@id, name=@name " &amp; _
  124. "WHERE id=@oldId", conn)
  125. da.DeleteCommand = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn)
  126. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  127. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  128. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  129. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  130. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  131. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  132. End Sub
  133. </code>
  134. <code lang="C#">
  135. public static void CreateSqlDataAdapter()
  136. {
  137. MySqlConnection conn = new MySqlConnection("Data Source=localhost;database=test");
  138. MySqlDataAdapter da = new MySqlDataAdapter();
  139. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  140. da.SelectCommand = new MySqlCommand("SELECT id, name FROM mytable", conn);
  141. da.InsertCommand = new MySqlCommand("INSERT INTO mytable (id, name) " +
  142. "VALUES (@id, @name)", conn);
  143. da.UpdateCommand = new MySqlCommand("UPDATE mytable SET id=@id, name=@name " +
  144. "WHERE id=@oldId", conn);
  145. da.DeleteCommand = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn);
  146. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  147. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  148. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  149. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  150. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  151. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  152. }
  153. </code>
  154. </example>
  155. </Ctor>
  156. <Ctor1>
  157. <summary>
  158. Initializes a new instance of the <see cref="MySqlDataAdapter"/> class with
  159. the specified <see cref="MySqlCommand"/> as the <see cref="SelectCommand"/>
  160. property.
  161. </summary>
  162. <param name="selectCommand">
  163. <see cref="MySqlCommand"/> that is a SQL SELECT statement or stored procedure and is set
  164. as the <see cref="SelectCommand"/> property of the <see cref="MySqlDataAdapter"/>.
  165. </param>
  166. <remarks>
  167. <para>
  168. When an instance of <see cref="MySqlDataAdapter"/> is created,
  169. the following read/write properties are set to the following initial
  170. values.
  171. </para>
  172. <list type="table">
  173. <listheader>
  174. <term>Properties</term>
  175. <term>Initial Value</term>
  176. </listheader>
  177. <item>
  178. <term>
  179. <see cref="MissingMappingAction"/>
  180. </term>
  181. <term>
  182. <B>MissingMappingAction.Passthrough</B>
  183. </term>
  184. </item>
  185. <item>
  186. <term>
  187. <see cref="MissingSchemaAction"/>
  188. </term>
  189. <term>
  190. <B>MissingSchemaAction.Add</B>
  191. </term>
  192. </item>
  193. </list>
  194. <para>
  195. You can change the value of any of these properties through a separate call
  196. to the property.
  197. </para>
  198. <para>
  199. When <B>SelectCommand</B> (or any of the other command properties) is assigned
  200. to a previously created <see cref="MySqlCommand"/>, the <B>MySqlCommand</B> is not cloned.
  201. The <B>SelectCommand</B> maintains a reference to the previously created <B>MySqlCommand</B>
  202. object.
  203. </para>
  204. </remarks>
  205. <example>
  206. The following example creates a <see cref="MySqlDataAdapter"/> and sets some of
  207. its properties.
  208. <code lang="vbnet">
  209. Public Sub CreateSqlDataAdapter()
  210. Dim conn As MySqlConnection = New MySqlConnection("Data Source=localhost;" &amp; _
  211. "database=test")
  212. Dim cmd as new MySqlCommand("SELECT id, name FROM mytable", conn)
  213. Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
  214. da.MissingSchemaAction = MissingSchemaAction.AddWithKey
  215. da.InsertCommand = New MySqlCommand("INSERT INTO mytable (id, name) " &amp; _
  216. "VALUES (@id, @name)", conn)
  217. da.UpdateCommand = New MySqlCommand("UPDATE mytable SET id=@id, name=@name " &amp; _
  218. "WHERE id=@oldId", conn)
  219. da.DeleteCommand = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn)
  220. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  221. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  222. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  223. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  224. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  225. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  226. End Sub
  227. </code>
  228. <code lang="C#">
  229. public static void CreateSqlDataAdapter()
  230. {
  231. MySqlConnection conn = new MySqlConnection("Data Source=localhost;database=test");
  232. MySqlCommand cmd = new MySqlCommand("SELECT id, name FROM mytable", conn);
  233. MySqlDataAdapter da = new MySqlDataAdapter(cmd);
  234. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  235. da.InsertCommand = new MySqlCommand("INSERT INTO mytable (id, name) " +
  236. "VALUES (@id, @name)", conn);
  237. da.UpdateCommand = new MySqlCommand("UPDATE mytable SET id=@id, name=@name " +
  238. "WHERE id=@oldId", conn);
  239. da.DeleteCommand = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn);
  240. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  241. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  242. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  243. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  244. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  245. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  246. }
  247. </code>
  248. </example>
  249. </Ctor1>
  250. <Ctor2>
  251. <summary>
  252. Initializes a new instance of the <see cref="MySqlDataAdapter"/> class with
  253. a <see cref="SelectCommand"/> and a <see cref="MySqlConnection"/> object.
  254. </summary>
  255. <param name="selectCommandText">
  256. A <b>String</b> that is a SQL SELECT statement or stored procedure to be used by
  257. the <see cref="SelectCommand"/> property of the <see cref="MySqlDataAdapter"/>.
  258. </param>
  259. <param name="connection">
  260. A <see cref="MySqlConnection"/> that represents the connection.
  261. </param>
  262. <remarks>
  263. <para>
  264. This implementation of the <see cref="MySqlDataAdapter"/> opens and closes a <see cref="MySqlConnection"/>
  265. if it is not already open. This can be useful in a an application that must call the
  266. <see cref="DbDataAdapter.Fill(DataSet)"/> method for two or more <B>MySqlDataAdapter</B> objects.
  267. If the <B>MySqlConnection</B> is already open, you must explicitly call
  268. <see cref="MySqlConnection.Close"/> or <see cref="MySqlConnection.Dispose()"/> to close it.
  269. </para>
  270. <para>
  271. When an instance of <see cref="MySqlDataAdapter"/> is created,
  272. the following read/write properties are set to the following initial
  273. values.
  274. </para>
  275. <list type="table">
  276. <listheader>
  277. <term>Properties</term>
  278. <term>Initial Value</term>
  279. </listheader>
  280. <item>
  281. <term>
  282. <see cref="MissingMappingAction"/>
  283. </term>
  284. <term>
  285. <B>MissingMappingAction.Passthrough</B>
  286. </term>
  287. </item>
  288. <item>
  289. <term>
  290. <see cref="MissingSchemaAction"/>
  291. </term>
  292. <term>
  293. <B>MissingSchemaAction.Add</B>
  294. </term>
  295. </item>
  296. </list>
  297. <para>
  298. You can change the value of any of these properties through a separate call
  299. to the property.
  300. </para>
  301. </remarks>
  302. <example>
  303. The following example creates a <see cref="MySqlDataAdapter"/> and sets some of
  304. its properties.
  305. <code lang="vbnet">
  306. Public Sub CreateSqlDataAdapter()
  307. Dim conn As MySqlConnection = New MySqlConnection("Data Source=localhost;" &amp; _
  308. "database=test")
  309. Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT id, name FROM mytable", conn)
  310. da.MissingSchemaAction = MissingSchemaAction.AddWithKey
  311. da.InsertCommand = New MySqlCommand("INSERT INTO mytable (id, name) " &amp; _
  312. "VALUES (@id, @name)", conn)
  313. da.UpdateCommand = New MySqlCommand("UPDATE mytable SET id=@id, name=@name " &amp; _
  314. "WHERE id=@oldId", conn)
  315. da.DeleteCommand = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn)
  316. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  317. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  318. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  319. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  320. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  321. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  322. End Sub
  323. </code>
  324. <code lang="C#">
  325. public static void CreateSqlDataAdapter()
  326. {
  327. MySqlConnection conn = new MySqlConnection("Data Source=localhost;database=test");
  328. MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, name FROM mytable", conn);
  329. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  330. da.InsertCommand = new MySqlCommand("INSERT INTO mytable (id, name) " +
  331. "VALUES (@id, @name)", conn);
  332. da.UpdateCommand = new MySqlCommand("UPDATE mytable SET id=@id, name=@name " +
  333. "WHERE id=@oldId", conn);
  334. da.DeleteCommand = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn);
  335. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  336. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  337. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  338. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  339. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  340. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  341. }
  342. </code>
  343. </example>
  344. </Ctor2>
  345. <Ctor3>
  346. <summary>
  347. Initializes a new instance of the <see cref="MySqlDataAdapter"/> class with
  348. a <see cref="SelectCommand"/> and a connection string.
  349. </summary>
  350. <param name="selectCommandText">
  351. A <see cref="string"/> that is a SQL SELECT statement or stored procedure to
  352. be used by the <see cref="SelectCommand"/> property of the <see cref="MySqlDataAdapter"/>.
  353. </param>
  354. <param name="selectConnString">The connection string</param>
  355. <remarks>
  356. <para>
  357. When an instance of <see cref="MySqlDataAdapter"/> is created,
  358. the following read/write properties are set to the following initial
  359. values.
  360. </para>
  361. <list type="table">
  362. <listheader>
  363. <term>Properties</term>
  364. <term>Initial Value</term>
  365. </listheader>
  366. <item>
  367. <term>
  368. <see cref="MissingMappingAction"/>
  369. </term>
  370. <term>
  371. <B>MissingMappingAction.Passthrough</B>
  372. </term>
  373. </item>
  374. <item>
  375. <term>
  376. <see cref="MissingSchemaAction"/>
  377. </term>
  378. <term>
  379. <B>MissingSchemaAction.Add</B>
  380. </term>
  381. </item>
  382. </list>
  383. <para>
  384. You can change the value of any of these properties through a separate call
  385. to the property.
  386. </para>
  387. </remarks>
  388. <example>
  389. The following example creates a <see cref="MySqlDataAdapter"/> and sets some of
  390. its properties.
  391. <code lang="vbnet">
  392. Public Sub CreateSqlDataAdapter()
  393. Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT id, name FROM mytable", "Data Source=localhost;database=test")
  394. Dim conn As MySqlConnection = da.SelectCommand.Connection
  395. da.MissingSchemaAction = MissingSchemaAction.AddWithKey
  396. da.InsertCommand = New MySqlCommand("INSERT INTO mytable (id, name) " &amp; _
  397. "VALUES (@id, @name)", conn)
  398. da.UpdateCommand = New MySqlCommand("UPDATE mytable SET id=@id, name=@name " &amp; _
  399. "WHERE id=@oldId", conn)
  400. da.DeleteCommand = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn)
  401. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  402. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  403. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  404. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name")
  405. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  406. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original
  407. End Sub
  408. </code>
  409. <code lang="C#">
  410. public static void CreateSqlDataAdapter()
  411. {
  412. MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, name FROM mytable", "Data Source=localhost;database=test");
  413. MySqlConnection conn = da.SelectCommand.Connection;
  414. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  415. da.InsertCommand = new MySqlCommand("INSERT INTO mytable (id, name) " +
  416. "VALUES (@id, @name)", conn);
  417. da.UpdateCommand = new MySqlCommand("UPDATE mytable SET id=@id, name=@name " +
  418. "WHERE id=@oldId", conn);
  419. da.DeleteCommand = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn);
  420. da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  421. da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  422. da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  423. da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name");
  424. da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  425. da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original;
  426. }
  427. </code>
  428. </example>
  429. </Ctor3>
  430. <DeleteCommand>
  431. <summary>
  432. Gets or sets a SQL statement or stored procedure used to delete records from the data set.
  433. </summary>
  434. <value>
  435. A <see cref="MySqlCommand"/> used during <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/> to delete records in the
  436. database that correspond to deleted rows in the <see cref="DataSet"/>.
  437. </value>
  438. <remarks>
  439. <para>
  440. During <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/>, if this property is not set and primary key information
  441. is present in the <see cref="DataSet"/>, the <B>DeleteCommand</B> can be generated
  442. automatically if you set the <see cref="SelectCommand"/> property and use the
  443. <see cref="MySqlCommandBuilder"/>. Then, any additional commands that you do not set are
  444. generated by the <B>MySqlCommandBuilder</B>. This generation logic requires key column
  445. information to be present in the <B>DataSet</B>.
  446. </para>
  447. <para>
  448. When <B>DeleteCommand</B> is assigned to a previously created <see cref="MySqlCommand"/>,
  449. the <B>MySqlCommand</B> is not cloned. The <B>DeleteCommand</B> maintains a reference
  450. to the previously created <B>MySqlCommand</B> object.
  451. </para>
  452. </remarks>
  453. <example>
  454. The following example creates a <see cref="MySqlDataAdapter"/> and sets the
  455. <see cref="SelectCommand"/> and <B>DeleteCommand</B> properties. It assumes you have already
  456. created a <see cref="MySqlConnection"/> object.
  457. <code lang="vbnet">
  458. Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter
  459. Dim da As MySqlDataAdapter = New MySqlDataAdapter()
  460. Dim cmd As MySqlCommand
  461. Dim parm As MySqlParameter
  462. ' Create the SelectCommand.
  463. cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn)
  464. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15)
  465. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15)
  466. da.SelectCommand = cmd
  467. ' Create the DeleteCommand.
  468. cmd = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn)
  469. parm = cmd.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id")
  470. parm.SourceVersion = DataRowVersion.Original
  471. da.DeleteCommand = cmd
  472. Return da
  473. End Function
  474. </code>
  475. <code lang="C#">
  476. public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn)
  477. {
  478. MySqlDataAdapter da = new MySqlDataAdapter();
  479. MySqlCommand cmd;
  480. MySqlParameter parm;
  481. // Create the SelectCommand.
  482. cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn);
  483. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15);
  484. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15);
  485. da.SelectCommand = cmd;
  486. // Create the DeleteCommand.
  487. cmd = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn);
  488. parm = cmd.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id");
  489. parm.SourceVersion = DataRowVersion.Original;
  490. da.DeleteCommand = cmd;
  491. return da;
  492. }
  493. </code>
  494. </example>
  495. </DeleteCommand>
  496. <InsertCommand>
  497. <summary>
  498. Gets or sets a SQL statement or stored procedure used to insert records into the data set.
  499. </summary>
  500. <value>
  501. A <see cref="MySqlCommand"/> used during <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/> to insert records into the
  502. database that correspond to new rows in the <see cref="DataSet"/>.
  503. </value>
  504. <remarks>
  505. <para>
  506. During <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/>, if this property is not set and primary key information
  507. is present in the <see cref="DataSet"/>, the <B>InsertCommand</B> can be generated
  508. automatically if you set the <see cref="SelectCommand"/> property and use the
  509. <see cref="MySqlCommandBuilder"/>. Then, any additional commands that you do not set are
  510. generated by the <B>MySqlCommandBuilder</B>. This generation logic requires key column
  511. information to be present in the <B>DataSet</B>.
  512. </para>
  513. <para>
  514. When <B>InsertCommand</B> is assigned to a previously created <see cref="MySqlCommand"/>,
  515. the <B>MySqlCommand</B> is not cloned. The <B>InsertCommand</B> maintains a reference
  516. to the previously created <B>MySqlCommand</B> object.
  517. </para>
  518. <note>
  519. If execution of this command returns rows, these rows may be added to the <B>DataSet</B>
  520. depending on how you set the <see cref="MySqlCommand.UpdatedRowSource"/> property of the <B>MySqlCommand</B> object.
  521. </note>
  522. </remarks>
  523. <example>
  524. The following example creates a <see cref="MySqlDataAdapter"/> and sets the
  525. <see cref="SelectCommand"/> and <B>InsertCommand</B> properties. It assumes you have already
  526. created a <see cref="MySqlConnection"/> object.
  527. <code lang="vbnet">
  528. Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter
  529. Dim da As MySqlDataAdapter = New MySqlDataAdapter()
  530. Dim cmd As MySqlCommand
  531. Dim parm As MySqlParameter
  532. ' Create the SelectCommand.
  533. cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn)
  534. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15)
  535. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15)
  536. da.SelectCommand = cmd
  537. ' Create the InsertCommand.
  538. cmd = New MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id, @name)", conn)
  539. cmd.Parameters.Add( "@id", MySqlDbType.VarChar, 15, "id" )
  540. cmd.Parameters.Add( "@name", MySqlDbType.VarChar, 15, "name" )
  541. da.InsertCommand = cmd
  542. Return da
  543. End Function
  544. </code>
  545. <code lang="C#">
  546. public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn)
  547. {
  548. MySqlDataAdapter da = new MySqlDataAdapter();
  549. MySqlCommand cmd;
  550. MySqlParameter parm;
  551. // Create the SelectCommand.
  552. cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn);
  553. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15);
  554. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15);
  555. da.SelectCommand = cmd;
  556. // Create the InsertCommand.
  557. cmd = new MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id,@name)", conn);
  558. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15, "id" );
  559. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15, "name" );
  560. da.InsertCommand = cmd;
  561. return da;
  562. }
  563. </code>
  564. </example>
  565. </InsertCommand>
  566. <UpdateCommand>
  567. <summary>
  568. Gets or sets a SQL statement or stored procedure used to updated records in the data source.
  569. </summary>
  570. <value>
  571. A <see cref="MySqlCommand"/> used during <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/> to update records in the
  572. database with data from the <see cref="DataSet"/>.
  573. </value>
  574. <remarks>
  575. <para>
  576. During <see cref="System.Data.Common.DbDataAdapter.Update(System.Data.DataSet)"/>, if this property is not set and primary key information
  577. is present in the <see cref="DataSet"/>, the <B>UpdateCommand</B> can be generated
  578. automatically if you set the <see cref="SelectCommand"/> property and use the
  579. <see cref="MySqlCommandBuilder"/>. Then, any additional commands that you do not set are
  580. generated by the <B>MySqlCommandBuilder</B>. This generation logic requires key column
  581. information to be present in the <B>DataSet</B>.
  582. </para>
  583. <para>
  584. When <B>UpdateCommand</B> is assigned to a previously created <see cref="MySqlCommand"/>,
  585. the <B>MySqlCommand</B> is not cloned. The <B>UpdateCommand</B> maintains a reference
  586. to the previously created <B>MySqlCommand</B> object.
  587. </para>
  588. <note>
  589. If execution of this command returns rows, these rows may be merged with the DataSet
  590. depending on how you set the <see cref="MySqlCommand.UpdatedRowSource"/> property of the <B>MySqlCommand</B> object.
  591. </note>
  592. </remarks>
  593. <example>
  594. The following example creates a <see cref="MySqlDataAdapter"/> and sets the
  595. <see cref="SelectCommand"/> and <B>UpdateCommand</B> properties. It assumes you have already
  596. created a <see cref="MySqlConnection"/> object.
  597. <code lang="vbnet">
  598. Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter
  599. Dim da As MySqlDataAdapter = New MySqlDataAdapter()
  600. Dim cmd As MySqlCommand
  601. Dim parm As MySqlParameter
  602. ' Create the SelectCommand.
  603. cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn)
  604. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15)
  605. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15)
  606. da.SelectCommand = cmd
  607. ' Create the UpdateCommand.
  608. cmd = New MySqlCommand("UPDATE mytable SET id=@id, name=@name WHERE id=@oldId", conn)
  609. cmd.Parameters.Add( "@id", MySqlDbType.VarChar, 15, "id" )
  610. cmd.Parameters.Add( "@name", MySqlDbType.VarChar, 15, "name" )
  611. parm = cmd.Parameters.Add("@oldId", MySqlDbType.VarChar, 15, "id")
  612. parm.SourceVersion = DataRowVersion.Original
  613. da.UpdateCommand = cmd
  614. Return da
  615. End Function
  616. </code>
  617. <code lang="C#">
  618. public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn)
  619. {
  620. MySqlDataAdapter da = new MySqlDataAdapter();
  621. MySqlCommand cmd;
  622. MySqlParameter parm;
  623. // Create the SelectCommand.
  624. cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn);
  625. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15);
  626. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15);
  627. da.SelectCommand = cmd;
  628. // Create the UpdateCommand.
  629. cmd = new MySqlCommand("UPDATE mytable SET id=@id, name=@name WHERE id=@oldId", conn);
  630. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15, "id" );
  631. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15, "name" );
  632. parm = cmd.Parameters.Add( "@oldId", MySqlDbType.VarChar, 15, "id" );
  633. parm.SourceVersion = DataRowVersion.Original;
  634. da.UpdateCommand = cmd;
  635. return da;
  636. }
  637. </code>
  638. </example>
  639. </UpdateCommand>
  640. <SelectCommand>
  641. <summary>
  642. Gets or sets a SQL statement or stored procedure used to select records in the data source.
  643. </summary>
  644. <value>
  645. A <see cref="MySqlCommand"/> used during <see cref="System.Data.Common.DbDataAdapter.Fill(DataSet)"/> to select records from the
  646. database for placement in the <see cref="DataSet"/>.
  647. </value>
  648. <remarks>
  649. <para>
  650. When <B>SelectCommand</B> is assigned to a previously created <see cref="MySqlCommand"/>,
  651. the <B>MySqlCommand</B> is not cloned. The <B>SelectCommand</B> maintains a reference to the
  652. previously created <B>MySqlCommand</B> object.
  653. </para>
  654. <para>
  655. If the <B>SelectCommand</B> does not return any rows, no tables are added to the
  656. <see cref="DataSet"/>, and no exception is raised.
  657. </para>
  658. </remarks>
  659. <example>
  660. The following example creates a <see cref="MySqlDataAdapter"/> and sets the
  661. <see cref="SelectCommand"/> and <B>InsertCommand</B> properties. It assumes you have already
  662. created a <see cref="MySqlConnection"/> object.
  663. <code lang="vbnet">
  664. Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter
  665. Dim da As MySqlDataAdapter = New MySqlDataAdapter()
  666. Dim cmd As MySqlCommand
  667. Dim parm As MySqlParameter
  668. ' Create the SelectCommand.
  669. cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn)
  670. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15)
  671. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15)
  672. da.SelectCommand = cmd
  673. ' Create the InsertCommand.
  674. cmd = New MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id, @name)", conn)
  675. cmd.Parameters.Add( "@id", MySqlDbType.VarChar, 15, "id" )
  676. cmd.Parameters.Add( "@name", MySqlDbType.VarChar, 15, "name" )
  677. da.InsertCommand = cmd
  678. Return da
  679. End Function
  680. </code>
  681. <code lang="C#">
  682. public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn)
  683. {
  684. MySqlDataAdapter da = new MySqlDataAdapter();
  685. MySqlCommand cmd;
  686. MySqlParameter parm;
  687. // Create the SelectCommand.
  688. cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn);
  689. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15);
  690. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15);
  691. da.SelectCommand = cmd;
  692. // Create the InsertCommand.
  693. cmd = new MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id,@name)", conn);
  694. cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15, "id" );
  695. cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15, "name" );
  696. da.InsertCommand = cmd;
  697. return da;
  698. }
  699. </code>
  700. </example>
  701. </SelectCommand>
  702. </docs>