public bool insertRowIntoApplicant(int AnsId, string Name){ string CS = Utilities.GetConnString(); using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("Insert Into ApplicantTable (AnswerableId, Name) values (@AnsId, @Name); SqlParameter paraAnsId = new SqlParameter() { ParameterName ="@AnsId", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Input, Value = AnsId }; cmd.Parameters.Add(paraAnsId); cmd.Parameters.Add(paraName); }}我从隐藏字段中获取值int getAnswerabelValue = Convert.ToInt32(hfAnswerableID.Value);if (dal_Obj1.insertRowIntoApplicant(getAnswerabelValue, Name){}我的问题是getAnswerabelValue有时可以为空,那么如何更改我的代码?
2 回答
白板的微信
TA贡献1883条经验 获得超3个赞
如果您的 db 列接受空值,那么您需要将 int 声明为可为空的 int
int? getAnswerabelValue = hfAnswerableID;
- 2 回答
- 0 关注
- 688 浏览
添加回答
举报
0/150
提交
取消