如何检查 Datarow 值是否为空 [英] How to check if Datarow value is null
本文介绍了如何检查 Datarow 值是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果需要返回 string
Convert.ToString(row["Int64_id"] ?? "")
或者应该像检查 DBNull.Value 一样.
Or should be like check with DBNull.Value.
需要比
if(row["Int64_id"] != DBNull.Value){...}else if{}
推荐答案
使用 DataRow.IsNull(string columnName)
if (!row.IsNull("Int64_id"))
{
// here you can use it safety
long someValue = (long)row["Int64_id"];
}
使用列的 index
或者如果您有 DataColumn
的实例,则可以对其进行重载.如果您确定 index
,请使用通常比其他选项更快的索引版本.
There are overloads for it using the index
of the column or if you have the instance of the DataColumn
. If you are sure about the index
, use the index version which tends to be faster than the other options.
这篇关于如何检查 Datarow 值是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文