如何赋空值的问题
相关代码如下:
在Models中定义如下:
public Nullable<double> WATERDEW_POINT {
get { return wATERDEW_POINT; }
set { wATERDEW_POINT = value; }
}
现在我txtWaterDew_point中不录入值则报错
Models.CHECKDATA_GASELEMENT mygas = new Models.CHECKDATA_GASELEMENT();
mygas.WATERDEW_POINT = txtWaterDew_point.Text.Trim() == "" ? Convert.ToDouble("") : Convert.ToDouble(txtWaterDew_point.Text.Trim());
------解决方案--------------------
这样写
mygas.WATERDEW_POINT = txtWaterDew_point.Text.Trim() == "" ? (double?)null : Convert.ToDouble(txtWaterDew_point.Text.Trim());