Get actual error from Dapper when running query

  Kiến thức lập trình

.Net 8

I’m using Dapper to perform CRUD operations. When I run an execute async query like so:

 var sql = "insert into table (`name`) values ('Adam')";
 var result = await connection.ExecuteAsync(sql);

I had an error take place because the result was equal to -1. No exception was thrown or anything. I ran the query in my MySQL workbench and got the following message:

  Error( 1364 ) HY000: "Field 'id' doesn't have a default value"

I fixed my table and now the query runs without error. My question is How do I get the exact error message in code instead of having to manually run the query in workbench?

Thanks

LEAVE A COMMENT