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

kriangkrai kongsamlee 5 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
Developer technologies | C#
{count} vote

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 79,106 Reputation points Volunteer Moderator
    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

  2. SurferOnWww 4,821 Reputation points
    2025-04-30T00:39:01.34+00:00
    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.