1

I'm developing a program in C# in which I make some inserts (load data infile) into a mysql table. How could I get the response the workbench shows me after each execution?

I'm interested in the 'Message' column, the one that shows me all the warnings.

Workbench screenshot

Thank you!

Asier Azkolain
  • 75
  • 1
  • 13
  • 1
    MySQL has a query for getting SQL warnings.. https://dev.mysql.com/doc/refman/5.7/en/show-warnings.html won't display affected/deleted records tho because these earn't warnings. – Raymond Nijland Feb 21 '18 at 12:20
  • for affected/deleted records information you need to do this https://stackoverflow.com/questions/10059158/get-affected-rows-on-executenonquery – Raymond Nijland Feb 21 '18 at 12:21
  • Possible duplicate of [Get affected rows on ExecuteNonQuery](https://stackoverflow.com/questions/10059158/get-affected-rows-on-executenonquery) – Fildor Feb 21 '18 at 12:25
  • I'll check Raymond's first link, it looks interesting. Regarding the other answers... I don't want to know only the number of affected rows (int), but the 'Message' column (String) with all the warnings, if there were any. – Asier Azkolain Feb 21 '18 at 14:05

1 Answers1

0

This is how I solved my problem... Thank you for the link, Raymond.

After I execute any statement (load data infile, in my case), I do the following:

MySqlCommand command2 = new MySqlCommand("SHOW WARNINGS", con);
using (MySqlDataReader reader = command2.ExecuteReader())
{
    while (reader.Read())
    {
        String level = reader["Level"].ToString();
        String code = reader["Code"].ToString();
        String message = reader["Message"].ToString();
    }
}

'show warnings' returns a result set in three columns: 'Level','Code' and 'Message'. This is how I get the data I needed.

I hope this is helpful ;)

Asier Azkolain
  • 75
  • 1
  • 13