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 MariaDB
An Azure managed MariaDB database service for app development and deployment.
56 questions
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
845 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.
11,005 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,461 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.