set the value of a int sqlparameter when the value of a drop down list is 0
if ddl has value of 0 want value of param null. tried error because null isnt int. thing compact. tried creating function cant return null if return type int
sqlparams[1] =
new sqlparameter("@fdno", ddlfd4.selectedvalue == "0" ? null :convert
.toint32( ddlfund4.selectedvalue));
m~
something this, return null non-int values, can modify how like.
static class stringextensions { public static int? tonullableint(this string value) { int intval; if (!int.tryparse(value, out intval)) { return null; } if (intval == 0) { return null; } return intval; } }
usage this
int? val = "".tonullableint(); // null val = "0".tonullableint(); // null val = "1".tonullableint(); // 1your code this.sqlparams[1] = new sqlparameter("@fdno", ddlfd4.selectedvalue.tonullableint()));
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment