Created
October 24, 2013 13:07
-
-
Save crystalclear/7136962 to your computer and use it in GitHub Desktop.
DBNull assign to a sqlparameter?
http://stackoverflow.com/questions/4555935/how-to-assign-null-to-a-sqlparameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SqlParameter[] parameters = new SqlParameter[1]; | |
SqlParameter planIndexParameter = new SqlParameter("@AgeIndex", SqlDbType.Int); | |
planIndexParameter.Value = (object)AgeItem.AgeIndex ?? DBNull.Value; | |
parameters[0] = planIndexParameter; | |
... | |
if (AgeItem.AgeIndex== null) | |
planIndexParameter.Value = DBNull.Value; | |
else | |
planIndexParameter.Value = AgeItem.AgeIndex; | |
... | |
foreach (SqlParameter parameter in sqlCmd.Parameters) | |
{ | |
if (parameter.Value == null) | |
{ | |
parameter.Value = DBNull.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment