MySqlDataReader将在C#中检索空值的问题 [英] MySQLDataReader retrieving Null value problem in c#

查看:1500
本文介绍了MySqlDataReader将在C#中检索空值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的工作在将出口MySQL的数据C#项目。出口是服务器中的任何数据库,所以我不会知道什么字段和表中的数据类型,我不会知道,如果在表中的字段允许空值与否。

I am currently working on a C# project that will export MySQL Data. The export is for any database within the server so I am not going to know what fields and the data types that are in the table and I am not going to know if a field in the table allows null values or not.

在测试过程中,我发现,出口工作正常,但如果字段允许空当MySQL的数据读取器去获取到这是空行它会显示错误SqlNullValueException,数据为空。

During testing, I have found that the export is working fine but if the field allows null when the mysql data reader goes gets to the row which is null it displays an error SqlNullValueException, data is null.

我曾尝试做如果(reader.getString(场)== NULL){} ,但它仍然是显示错误。

I have tried doing if (reader.getString(field) == null) {} but it is still displaying the error.

我如何应付与数据库中的Null值。任何帮助。

How do I cope with Null values in the database.

谢谢您可以提供。

推荐答案

您需要明确的读者这么测试空:

You need to test for null explicitly in a reader so:

if (!reader.IsDbNull(field)) {
    var value = reader.GetString(field);
    // ... do stuff here ...
}

这篇关于MySqlDataReader将在C#中检索空值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆