@@ -191,6 +191,72 @@ public void InsertWithDataSet()
191
191
}
192
192
}
193
193
194
+ [ Fact ]
195
+ public void BatchUpdate ( )
196
+ {
197
+ using ( var ds = new DataSet ( ) )
198
+ using ( var da = new MySqlDataAdapter ( "SELECT * FROM data_adapter" , m_connection ) )
199
+ {
200
+ da . Fill ( ds ) ;
201
+
202
+ da . UpdateCommand = new MySqlCommand ( "UPDATE data_adapter SET int_value=@int, text_value=@text WHERE id=@id" , m_connection )
203
+ {
204
+ Parameters =
205
+ {
206
+ new MySqlParameter ( "@int" , MySqlDbType . Int32 ) { Direction = ParameterDirection . Input , SourceColumn = "int_value" } ,
207
+ new MySqlParameter ( "@text" , MySqlDbType . String ) { Direction = ParameterDirection . Input , SourceColumn = "text_value" } ,
208
+ new MySqlParameter ( "@id" , MySqlDbType . Int64 ) { Direction = ParameterDirection . Input , SourceColumn = "id" } ,
209
+ } ,
210
+ UpdatedRowSource = UpdateRowSource . None ,
211
+ } ;
212
+
213
+ da . UpdateBatchSize = 10 ;
214
+
215
+ var dt = ds . Tables [ 0 ] ;
216
+ dt . Rows [ 0 ] [ 1 ] = 2 ;
217
+ dt . Rows [ 0 ] [ 2 ] = "two" ;
218
+ dt . Rows [ 1 ] [ 1 ] = 3 ;
219
+ dt . Rows [ 1 ] [ 2 ] = "three" ;
220
+ dt . Rows [ 2 ] [ 1 ] = 4 ;
221
+ dt . Rows [ 2 ] [ 2 ] = "four" ;
222
+
223
+ da . Update ( ds ) ;
224
+ }
225
+
226
+ Assert . Equal ( new [ ] { "two" , "three" , "four" } , m_connection . Query < string > ( "SELECT text_value FROM data_adapter ORDER BY id" ) ) ;
227
+ }
228
+
229
+
230
+ [ Fact ]
231
+ public void BatchInsert ( )
232
+ {
233
+ using ( var ds = new DataSet ( ) )
234
+ using ( var da = new MySqlDataAdapter ( "SELECT * FROM data_adapter" , m_connection ) )
235
+ {
236
+ da . Fill ( ds ) ;
237
+
238
+ da . InsertCommand = new MySqlCommand ( "INSERT INTO data_adapter(int_value, text_value) VALUES(@int, @text);" , m_connection )
239
+ {
240
+ Parameters =
241
+ {
242
+ new MySqlParameter ( "@int" , MySqlDbType . Int32 ) { Direction = ParameterDirection . Input , SourceColumn = "int_value" } ,
243
+ new MySqlParameter ( "@text" , MySqlDbType . String ) { Direction = ParameterDirection . Input , SourceColumn = "text_value" } ,
244
+ } ,
245
+ UpdatedRowSource = UpdateRowSource . None ,
246
+ } ;
247
+
248
+ da . UpdateBatchSize = 10 ;
249
+
250
+ var dt = ds . Tables [ 0 ] ;
251
+ dt . Rows . Add ( 0 , 2 , "two" ) ;
252
+ dt . Rows . Add ( 0 , 3 , "three" ) ;
253
+ dt . Rows . Add ( 0 , 4 , "four" ) ;
254
+
255
+ da . Update ( ds ) ;
256
+ }
257
+
258
+ Assert . Equal ( new [ ] { null , "" , "one" , "two" , "three" , "four" } , m_connection . Query < string > ( "SELECT text_value FROM data_adapter ORDER BY id" ) ) ;
259
+ }
194
260
readonly MySqlConnection m_connection ;
195
261
}
196
262
}
0 commit comments