从DataRow中读取一个datetime类型的数据时,发生“无效文件格式”的错误。
在赋值时就会出现该错误。比如:
object myCell=dr["EffectiveDate"];
该异常用try无法捕获。
但是在主窗口进行上述操作时没有错误发生,当把dr传入到另一个窗体中时,才会出现上述异常。
问题点数:20、回复次数:8Top
1 楼saucer(思归)回复于 2003-02-04 11:45:55 得分 10
try
object myCell=dr.IsDBNull(dr.GetOrdinal("EffectiveDate"))? null:dr["EffectiveDate"];Top
2 楼mur(murmur)回复于 2003-02-04 13:18:59 得分 0
肯定不是DBNull。在监视窗口中可以正确显示出2002/5/8。但是一运行就说“无效文件格式”Top
3 楼lbx1979(Love Arsenal)回复于 2003-02-04 13:40:33 得分 10
直接用datatime类型不行吗?Top
4 楼mur(murmur)回复于 2003-02-04 13:57:52 得分 0
在数据库中设置的类型就是datetime。Top
5 楼saucer(思归)回复于 2003-02-04 14:26:56 得分 0
try
DateTime myCell =(DateTime) dr["EffectiveDate"];
or
DateTime myCell= dr.GetDateTime(dr.GetOrdinal("EffectiveDate"));Top
6 楼mur(murmur)回复于 2003-02-05 12:47:23 得分 0
多谢 思归
但是第一种方法还是出错。
第二种方法中,dr没有GetOrdinal方法。
其实dataset中的数据曾经可以正常读取。但是一旦将一条datarow传递到一个新窗口中就会出现上述错误。其他类型的字段不会出错。
//将dr中的数据填写到对应位置。
//必填项目
this.ADNoText.Text=this.dr["ADNo"].ToString();
this.ReviseNoText.Text=this.dr["ReviseNo"].ToString();
this.HeaderText.Text=this.dr["Header"].ToString();
this.ApplyToText.Text=this.dr["ApplyTo"].ToString();
this.MainRefADNoText.Text=this.dr["MainRefADNo"].ToString();
this.MainRefReviseNoText.Text=this.dr["MainRefReviseNo"].ToString();
this.ReferenceText.Text=this.dr["Reference"].ToString();
this.ReasonMethodRBox.Rtf=FillRTF(this.dr["ReasonMethod"].ToString());
try/////////////////无效文件格式
{
if (this.dr["EffectiveDate"].ToString()!="")
{
System.DateTime dtEff=Convert.ToDateTime(this.dr["EffectiveDate"]);
this.txtEffectiveYear.Text=dtEff.Year.ToString();
this.txtEffectiveMonth.Text=dtEff.Month.ToString();
this.txtEffectiveDay.Text=dtEff.Day.ToString();
}
else
{
this.txtEffectiveYear.Text="";
this.txtEffectiveMonth.Text="";
this.txtEffectiveDay.Text="";
}
}
catch(Exception ee)
{
string hayerr=ee.Message;
}
Top
7 楼mur(murmur)回复于 2003-02-05 12:48:07 得分 0
try上面的部分都没有出错。Top
8 楼mur(murmur)回复于 2003-02-07 10:19:33 得分 0
问题解决了。
是这行出的问题。
this.ReasonMethodRBox.Rtf=FillRTF(this.dr["ReasonMethod"].ToString());
谢谢大家。Top




