sqlparameter

Assign null to a SqlParameter

岁酱吖の 提交于 2019-11-26 01:06:43
问题 The following code gives an error - \"No implicit conversion from DBnull to int.\" SqlParameter[] parameters = new SqlParameter[1]; SqlParameter planIndexParameter = new SqlParameter(\"@AgeIndex\", SqlDbType.Int); planIndexParameter.Value = (AgeItem.AgeIndex== null) ? DBNull.Value : AgeItem.AgeIndex; parameters[0] = planIndexParameter; 回答1: The problem is that the ?: operator cannot determine the return type because you are either returning an int value or a DBNull type value, which are not

Assign null to a SqlParameter

匆匆过客 提交于 2019-11-26 00:57:36
The following code gives an error - "No implicit conversion from DBnull to int." SqlParameter[] parameters = new SqlParameter[1]; SqlParameter planIndexParameter = new SqlParameter("@AgeIndex", SqlDbType.Int); planIndexParameter.Value = (AgeItem.AgeIndex== null) ? DBNull.Value : AgeItem.AgeIndex; parameters[0] = planIndexParameter; Chris Taylor The problem is that the ?: operator cannot determine the return type because you are either returning an int value or a DBNull type value, which are not compatible. You can of course cast the instance of AgeIndex to be type object which would satisfy