DBNULL 的问题 SqlDataReader reader = ....DateTime d = DateTime.MinValue; //DateTime类型不能赋为null,所以赋初值为.Net中DateTime类型的最小值if( reader[0] == DBNull.Value ) d = (DateTime)reader[0]; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我从数据库中获取得的字段是container_time_in 如何判断它是不是DBNull.Value.其中container_time_in 十DateTime类型. 是想在Sql中呢,还是在程序中呢在前者,可以这样:string strQuery="select * from yourtable where yourfield is not null";如果是后者,用try……catch进行捕获。 try{ContainerMFService cmfService=new ContainerMFService(); ContainerMFDataSet cmfDs=new ContainerMFDataSet(); cmfDs=(ContainerMFDataSet)SerializeDataSet.Deserialize(cmfService.getContainerByContainerId(this.textBox3.Text.Trim().ToString(),"1556"),"ContainerMF"); ContainerMFDataSet.ContainerMFRow r=(ContainerMFDataSet.ContainerMFRow)cmfDs.ContainerMF.Rows[0]; if(r.container_empty_time==DBNull.Value) { this.txtEmptyTime.Text=r.container_empty_time.ToString("yyyy-MM-dd"); } if(r.container_out_time.Equals(DBNull.Value)) { this.txtOutTime.Text=r.container_out_time.ToString("yyyy-MM-dd"); }}catch(Exception eX){MessageBox.show(EX.Message);}我这里有些特殊,在程序中进行判断,其他字段不为空,而这个字段有时候为空,有时候不为空,所以无法再server中判断.通过异常是扑或了,但是怎么处理呢?假如这样if(container_in_time!=DBNull.Value){MessageBox.show("there is no container");}else{MessageBox.show("");} 如果嫌麻烦,那么直接try catch不就行了吗?try{ this.txtEmptyTime.Text=r.container_empty_time.ToString("yyyy-MM-dd");}catch{ MessageBox.show("there is no container"); } 关于自定义winform 按钮事件,重复问题 Winform 怎么设置控件的背景透名 c# 使用odbc源调用存储过程 关于NetworkStream类 write方法 升星散分 C#怎么创建数组? 如何把这条查询语句传到父窗口?困扰了我好久的问题。 一个拖放的问题 关于如何用混淆器混淆安装文件呢? 用oledbdataadapter连接加密的access数据库的问题? 关于DataGrid和CrystalReport .net可以为掌上电脑程序吗?
在前者,可以这样:
string strQuery="select * from yourtable where yourfield is not null";
如果是后者,用
try……catch进行捕获。
{
ContainerMFService cmfService=new ContainerMFService();
ContainerMFDataSet cmfDs=new ContainerMFDataSet();
cmfDs=(ContainerMFDataSet)SerializeDataSet.Deserialize(cmfService.getContainerByContainerId(this.textBox3.Text.Trim().ToString(),"1556"),"ContainerMF"); ContainerMFDataSet.ContainerMFRow r=(ContainerMFDataSet.ContainerMFRow)cmfDs.ContainerMF.Rows[0];
if(r.container_empty_time==DBNull.Value)
{
this.txtEmptyTime.Text=r.container_empty_time.ToString("yyyy-MM-dd");
}
if(r.container_out_time.Equals(DBNull.Value))
{
this.txtOutTime.Text=r.container_out_time.ToString("yyyy-MM-dd");
}
}
catch(Exception eX)
{
MessageBox.show(EX.Message);
}我这里有些特殊,在程序中进行判断,其他字段不为空,而这个字段有时候为空,有时候不为空,所以无法再server中判断.通过异常是扑或了,但是怎么处理呢?
假如这样if(container_in_time!=DBNull.Value)
{MessageBox.show("there is no container");}
else
{
MessageBox.show("");
}
try
{
this.txtEmptyTime.Text=r.container_empty_time.ToString("yyyy-MM-dd");
}
catch
{
MessageBox.show("there is no container");
}