File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
docs/content/api/MySqlConnector Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,23 @@ Example code:
17
17
// https://dev.mysql.com/doc/refman/8.0/en/insert-select.html
18
18
var dataTable = GetDataTableFromExternalSource ();
19
19
20
+ // open the connection
20
21
using var connection = new MySqlConnection (" ...;AllowLoadLocalInfile=True" );
21
22
await connection .OpenAsync ();
23
+
24
+ // attach an event handler to retrieve warnings/errors
25
+ IReadOnlyList < MySqlError > errors = Array .Empty <MySqlError >();
26
+ void InfoMessageHandler (object sender , MySqlInfoMessageEventArgs args ) => errors = args .Errors ;
27
+ connection .InfoMessage += InfoMessageHandler ;
28
+
29
+ // bulk copy the data
22
30
var bulkCopy = new MySqlBulkCopy (connection );
23
31
bulkCopy .DestinationTableName = " some_table_name" ;
24
32
await bulkCopy .WriteToServerAsync (dataTable );
33
+
34
+ // check for errors
35
+ connection .InfoMessage -= InfoMessageHandler ;
36
+ if (errors .Count != 0 ) { /* handle errors */ }
25
37
```
26
38
27
39
``` csharp
Original file line number Diff line number Diff line change @@ -29,11 +29,23 @@ namespace MySqlConnector
29
29
/// // https://dev.mysql.com/doc/refman/8.0/en/insert-select.html
30
30
/// var dataTable = GetDataTableFromExternalSource();
31
31
///
32
+ /// // open the connection
32
33
/// using var connection = new MySqlConnection("...;AllowLoadLocalInfile=True");
33
34
/// await connection.OpenAsync();
35
+ ///
36
+ /// // attach an event handler to retrieve warnings/errors
37
+ /// IReadOnlyList<MySqlError> errors = Array.Empty<MySqlError>();
38
+ /// void InfoMessageHandler(object sender, MySqlInfoMessageEventArgs args) => errors = args.Errors;
39
+ /// connection.InfoMessage += InfoMessageHandler;
40
+ ///
41
+ /// // bulk copy the data
34
42
/// var bulkCopy = new MySqlBulkCopy(connection);
35
43
/// bulkCopy.DestinationTableName = "some_table_name";
36
44
/// await bulkCopy.WriteToServerAsync(dataTable);
45
+ ///
46
+ /// // check for errors
47
+ /// connection.InfoMessage -= InfoMessageHandler;
48
+ /// if (errors.Count != 0) { /* handle errors */ }
37
49
/// </code>
38
50
/// </summary>
39
51
/// <remarks><para><strong>Note:</strong> This API is a unique feature of MySqlConnector; you must
You can’t perform that action at this time.
0 commit comments