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.
64 questions
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
986 questions
Developer technologies C#
11,567 questions
2 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2023-03-30T15:35:43.57+00:00 -
SurferOnWww 4,631 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