在C#中打开与Mysql的连接时,无法将对象从DBSQL转换为其他类型

c0vxltue  于 12个月前  发布在  Mysql
关注(0)|答案(1)|浏览(117)
Line 27: try
Line 28: {
Line 29:     Conn.Open();
Line 30:     MySqlReader = cmd.ExecuteReader();
Line 31:     if (MySqlReader.Read() == true)

字符串
我尝试更改Mysql.dll,并添加了一个引用到Web配置,但它不起作用。我在打开连接时收到此错误:
'第29行:Conn.Open();'

ddarikpa

ddarikpa1#

在阅读数据时检查数据库:

int value = MySqlReader.IsDBNull(columnIndex) ? defaultValue : MySqlReader.GetInt32(columnIndex);

try
{
    Conn.Open();
    MySqlReader = cmd.ExecuteReader();
    while (MySqlReader.Read())
    {
        // Example of reading an integer, with a check for DBNull
        int someColumnValue = MySqlReader.IsDBNull(columnIndex) ? 0 : MySqlReader.GetInt32(columnIndex);
        // Process other columns similarly
    }
}
catch (Exception ex)
{

// Log the exception details for debugging
Console.WriteLine(ex.Message);

}
finally
{
    // Close the reader and connection if open
    MySqlReader?.Close();
    Conn?.Close();
}

字符串

相关问题