1

I'm struggling to understand why selecting two fields in this table return an exception.

List<Data> queryResult = new List<Data>;

using(var localConnection = new MySqlConnection(str_connection_string))
{
    queryResult = localConnection.Query<Data>("SELECT int_id, description from product").Tolist();





System.NullReference Exception - Object reference not set to an instance of an object  
at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex)
   at MySql.Data.MySqlClient.MySqlDataReader.Read()
   at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)
   at TestLookup.ExecuteByCustomer(Int32 clienteMasterId, String str_connection_string)

Throw always happens when including description in the query, other fields do not present this issue, and there's no null or empty values when querying the database through Workbench.

RChamy
  • 31
  • 3
  • Uhmm Description seems to be a special keyword. Try putting it between backticks keyboard ALT+096 – Steve Nov 10 '21 at 18:23

0 Answers0