c# error when connect to mysql "Object cannot be cast from DBNull to other types" (mariadb 10.3)

kriangkrai kongsamlee 0 Reputation points
2023-03-27T04:27:32.28+00:00

Object cannot be cast from DBNull to other types" (mariadb 10.3)

Azure Database for MariaDB
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
722 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,345 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,481 Reputation points
    2023-03-30T15:35:43.57+00:00

    That is correct. when a column value is null, the object DBNull is returned rather than a typed value. You must first test that the column value is not null via the api before accessing as the desired type.

    0 comments No comments