tryobject myCell=dr.IsDBNull(dr.GetOrdinal("EffectiveDate"))? null:dr["EffectiveDate"];

解决方案 »

  1.   

    肯定不是DBNull。在监视窗口中可以正确显示出2002/5/8。但是一运行就说“无效文件格式”
      

  2.   

    在数据库中设置的类型就是datetime。
      

  3.   

    tryDateTime myCell =(DateTime) dr["EffectiveDate"];orDateTime myCell= dr.GetDateTime(dr.GetOrdinal("EffectiveDate"));
      

  4.   

    多谢 思归 
    但是第一种方法还是出错。
    第二种方法中,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;
    }
      

  5.   

    问题解决了。
    是这行出的问题。
    this.ReasonMethodRBox.Rtf=FillRTF(this.dr["ReasonMethod"].ToString());
    谢谢大家。