【发布时间】:2014-08-24 13:36:05
【问题描述】:
我的数据库中有一个名为“患者”的表。该表有一个名为 DOB 的列,并且 Allow Null 值为 true。这是表结构:
- Id int IDENTITY(1,1) NOT NULL,
- 名字 nvarchar(50) NULL,
- 姓氏 nvarchar(50) NULL,
- 性位 NULL,
- 重量小数(18, 0) NULL,
- 高度小数(18, 0) NULL,
- 出生日期 NULL,
- PatientId nvarchar(50) 非空
我正在使用 LinqToSql。问题是,当我想为 DOB 列设置 null 时,Visual Studio 会告诉 DOB 不可为空。这是我的代码:
Patient tblPatient = new Patient();
if (txtYear.Text != "" && txtMonth.Text != "" && txtDay.Text != "")
tblPatient.DOB = Utility.ConvertPersianDateToGregorianDate(txtYear.Text + "/" + txtMonth.Text + "/" + txtDay.Text);
else
tblPatient.DOB = null; // The error is in this line
【问题讨论】:
-
在你的班级
PatientDOB属性的类型是什么? -
@FelipeOriani,它是
DateTime。 -
大卫的遮阳篷会解决你的问题:)
标签: c# sql sql-server linq-to-sql