如果在数据表c中为null值或零存储,如何检查整数列# [英] how to check integer column if it is null value or zero store in datatable c#
本文介绍了如果在数据表c中为null值或零存储,如何检查整数列#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,当我插入仅值字符串时,它存储整数列的空值。每当我更新任何整数列时,都会有一些字符串列和一些整数,它会将所有整数列更新为零。
在我的代码中,我想检查它是否为零/零。我使用DBNull.Value,但它只检查null而不是零我想一次检查两个。
任何人都可以帮我。
我的代码如下
I have one table in which it store null value for integer column when I insert the value only string. There are some string column and some integer whenever I update any integer column it update all the integer column by zero.
In my code I want to check the if it is null/zero. I use the DBNull.Value but its only check for null not for zero i want to check both at a time.
Can anyone help me please.
My code is as follow
if (dt.Rows[i]["IsSaved"]!=DBNull.Value && dt.Rows[i]["IsApplied"]!=DBNull.Value)
{
str += " <input style=\"border: none;background-color:gray;\" id=\"unsave" + JobID + "\" type=\"button\" class=\"log_in\" value=\"UNSAVE\" onclick=\"ShowCurrentTime(" + JobID + ",'unsave')\"/>" +
" <input style=\"border: none;background-color:gray;\" id=\"applied" + JobID + "\" type=\"button\" class=\"sign_up_cc\" value=\"APPLIED\" />";
}
推荐答案
if (dt.Rows[i]["IsSaved"]!=DBNull.Value && dt.Rows[i]["IsApplied"]!=DBNull.Value && dt.Rows[i]["IsSaved"]!=0 && dt.Rows[i]["IsApplied"]!=0)
{
str += " <input style=\"border: none;background-color:gray;\" id=\"unsave" + JobID + "\" type=\"button\" class=\"log_in\" value=\"UNSAVE\" onclick=\"ShowCurrentTime(" + JobID + ",'unsave')\"/>" +
" <input style=\"border: none;background-color:gray;\" id=\"applied" + JobID + "\" type=\"button\" class=\"sign_up_cc\" value=\"APPLIED\" />";
}
我使用此代码解决了这个问题
I solve this problem using this code
if ((dt.Rows[i]["IsSaved"].Equals(DBNull.Value) ? 0 : Convert.ToInt32(dt.Rows[i]["IsSaved"] ?? "0")) != 0 && (dt.Rows[i]["IsApplied"].Equals(DBNull.Value) ? 0 : Convert.ToInt32(dt.Rows[i]["IsApplied"] ?? "0")) != 0)
{
str += " <input style=\"border: none;background-color:gray;\" id=\"unsave" + JobID + "\" type=\"button\" class=\"log_in btn_sm\" value=\"UNSAVE\" onclick=\"ShowCurrentTime(" + JobID + ",'unsave')\"/>" +
" <input style=\"border: none;background-color:gray;\" id=\"applied" + JobID + "\" type=\"button\" class=\"sign_up_cc btn_sm\" value=\"APPLIED\" />";
}
这篇关于如果在数据表c中为null值或零存储,如何检查整数列#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文