如何处理空值 [英] How to handle null value

查看:115
本文介绍了如何处理空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我打算查询一个表并将一些值插入另一个表.用值查询表没有问题.但是,如果该值为null,则将引发invalidcastexception-无法将类型为'System.DBNull'的对象转换为类型为'System.String'

I had an intention to query one table and insert some value into another table. There is no problem in querying the table with value. But if the value is null, it throws a invalidcastexception - Unable to cast object of type 'System.DBNull' to type 'System.String'

我的部分代码如下.

任何人都可以让我知道如何处理空数据吗?

Can anyone let me know how to handle data that is null?

谢谢

(reader.Read())

while (reader.Read())

{

( int i = 0; i< 20; i ++)

for (int i=0;i<20;i++)

{

if (reader.GetString(i)!= null )

if (reader.GetString(i) != null)

{

result = reader.GetString(i).ToString();

result = reader.GetString(i).ToString();

}

其他

else

{

result = " " ;

result = " ";

}

 

data =数据+ " \"+" +结果+ " + \&;'," ;

data = data + "'\" + " + result + " + \"', ";

}

 

data = data.Substring(0,data.Length-2);

data = data.Substring(0, data.Length - 2);

}

MessageBox .Show(data);

MessageBox.Show(data);

//关闭阅读器和连接

// close reader and connection

reader.Close();

reader.Close();

conn.Close();

conn.Close();

推荐答案

可以替换

if (reader.GetString(i)!= null )

Can you replace

if (reader.GetString(i) != null)


这篇关于如何处理空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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