从DataRow中读取一个datetime类型的数据时,发生“无效文件格式”的错误。 tryobject myCell=dr.IsDBNull(dr.GetOrdinal("EffectiveDate"))? null:dr["EffectiveDate"]; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 肯定不是DBNull。在监视窗口中可以正确显示出2002/5/8。但是一运行就说“无效文件格式” 在数据库中设置的类型就是datetime。 tryDateTime myCell =(DateTime) dr["EffectiveDate"];orDateTime myCell= dr.GetDateTime(dr.GetOrdinal("EffectiveDate")); 多谢 思归 但是第一种方法还是出错。第二种方法中,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;} 问题解决了。是这行出的问题。this.ReasonMethodRBox.Rtf=FillRTF(this.dr["ReasonMethod"].ToString());谢谢大家。 C#中 [] 怎么转义 使用Dundas WinChart绘图碰到的问题 数据库查询多个条件 请教各位朋友 怎么把C#的数组存到oracle数据库的表中? bit字段对应c#中的数据类型 请问给位高手,在C#里面怎样判断一个在客户端的文件是否存在。(心急人上) 如何统计CS文件中公有类,私有类,受保护类的个数? 错哪了? VS2017打包部署项目时出现“无法访问你试图使用的功能所在的CD-ROM或其他可移动式磁盘”的问题。。 请问如何才能移除数据集中的约束(ForeignKeyConstraint)? C#读取URL里面的XML数据问题
但是第一种方法还是出错。
第二种方法中,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;
}
是这行出的问题。
this.ReasonMethodRBox.Rtf=FillRTF(this.dr["ReasonMethod"].ToString());
谢谢大家。