With dm.ADOq do
   begin
   Close;
   SQL.Clear;
   time:= strtodatetime(edit39.Text);
   SQL.Add(  'update yuangong set shijian=to_date('''+FormatdateTime('yyyy-mm-dd ',time)+''', 'yyyy-mm-dd') Where xingming='''+edit15.Text+'''  ');
   execsql;
   end;系统总是提示错误  , 请问该怎样修改数据库中的时间字段的值。

解决方案 »

  1.   

    SQL.Add('update yuangong set shijian='+Quotedstr(StrToDateTime(edit39.Text))+' where xingming='+Quotedstr(edit15.Text));
      

  2.   

    这个也不行  因为shijian字段是 date类型   不匹配 
      

  3.   

    哦,我写错了,直接像下面这样即可。
    只要edit39输入的是符合日期的格式就行了,至于是不是符合日期格式自己要先判断
     
    ... shijian='+Quotedstr(edit39.Text)+' ...
      

  4.   

    Quotedstr 返回值应该是个 string类型啊   shijian在数据库里是 date类型  不匹配啊 
      

  5.   

    实验出真理,去试试吧,只要输入格式正确就行Quotedstr是为了处理单引号问题,最终的语句像这样的
    update yuangong set shijian='2012-8-23' where xingming='XX'
      

  6.   

    update yuangong set shijian='2012-8-23' where xingming='XX'  直接在数据库里用可以  但是在delphi里用shijian='+Quotedstr(edit39.Text)+' .就不行了! 郁闷!  总提示不匹配 
      

  7.   

     改成这个就好了   SQL.Add( 'update yuangong set shijian=to_date('''+FormatdateTime('yyyy-mm-dd ',time)+''',' 'yyyy-mm-dd'') Where xingming='''+edit15.Text+''' ');''yyyy-mm-dd''加两个引号 就行了  。 自己能给自己分不!