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.
c# error when connect to mysql "Object cannot be cast from DBNull to other types" (mariadb 10.3)
kriangkrai kongsamlee
5
Reputation points
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.
60 questions
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
949 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,431 questions
2 answers
Sort by: Most helpful
-
-
SurferOnWww 4,391 Reputation points
2025-04-30T00:39:01.34+00:00 If you use the Connector/NET (i.e., MySql.Data), try using the MySqlConnector instead of MySql.Data.
References:
MySQL Connector fails to connect to MariaDB 10.10.2
MySqlConnection.Open() System.InvalidCastException: Object cannot be cast from DBNull to other types