请大家指教:环境:后台SQL Server2000,前台delphi7.0;
数据库:company;    表:employee;    字段:出生日期       类型:DateTime
问题:DataModuleMain.Tab_employee.FieldByName('出生日期').AsDateTime:=StrToDateTime(edit3.Text);
一运行到这里就出错,其他地方调试都正确。
错误信息:Project main.exe raised exception class EconvertError with message ’’’ is not a valid date and time’. 百思不得其解,请大家指教啊。

解决方案 »

  1.   

    DataModuleMain.Tab_employee.FieldByName('出生日期').AsDateTime:=StrToDateTime(edit3.Text);
    改为:
    DataModuleMain.Tab_employee.FieldByName('出生日期').AsDateTime:=StrToDate(edit3.Text);StrToDateTime()不要加Time就可以了.
      

  2.   

    edit3.Text是空值吧
    ’’ is not a valid date and timeDataModuleMain.Tab_employee.FieldByName('出生日期').Value:=DateToStr(date);
      

  3.   

    上面两种都试过了,无效阿!黑仔:edit3.text是一个输入框,把输入的日期添加到数据库的表中,输入时不可能是空值阿,另外,我试过了好几种输入的格式,都不行。所以困惑死了。
      

  4.   

    从你的错误信息:Project main.exe raised exception class EconvertError with message ’’’ is not a valid date and time’看,应该是试图将空值转换为TDateTime时产生异常,不妨在DataModuleMain.Tab_employee.FieldByName('出生日期').AsDateTime:=StrToDateTime(edit3.Text)前加上showmessage(edit3.Text);看看,如果不是空值,那可能是其他地方出错吧
      

  5.   

    DataModuleMain.Tab_employee.FieldByName('出生日期').value:=formatdatetime('yyyy-mm-dd',strtodatetime(edit1.text));
      

  6.   

    谢谢各位黑仔:我用您的方法试过了,譬如我在edit3.text中输入1979-10-26,ShowMessage会弹出1979-10-26,这说明输入的不是空值,对吧。杰克.逊:程序通过,谢谢!非常感谢各位。