Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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\" />";
                                 }
Posted

C#
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\" />";
                                 }
 
Share this answer
 
Comments
asplover1 11-Dec-15 6:00am    
Thanks for reply
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\" />";
                         }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900