procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
begin
  //qian这个字段[qian] [numeric](8, 2) NOT NULL
  i:=ExecSql('Update hytab set qian=convert(numeric(8,2),:qian) where kh=:kh',VarArrayOf([19.50,600699]));
  //或i:=ExecSql('Update hytab set qian=:qian where kh=600699',VarArrayOf([19.50]));
  showMessage(IntToStr(i));
end;function TForm1.ExecSql(sqlstr:String; vParam:Variant):integer;
var
  I:integer;
  tmpCommand:TADOCommand;
begin
  Result:=0;
  tmpCommand:=TADOCommand.Create(nil);
  try
    with tmpCommand do
    begin
      CommandTimeout:=300;
      Connection:=ADOConnection1;
      CommandText:=sqlstr;
      tmpCommand.Execute(i,vParam);
      Result:= i;
    end;
  finally
    tmpCommand.Free;
  end;
end;end.报  错
First chance exception at $7C812A7B. Exception class EOleException with message '参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。'. Process Project1.exe (432)
同样代码在D2007却没任何问题...............玩死人啊!!要不是delphi2007的scktsrvr用了N小时后经常平白无故报10054我也不想吃这个螃蟹

解决方案 »

  1.   

    我模拟了一下你的情况并且把你的代码在我机器上测试了下没有问题。
    CREATE TABLE [dbo].[hytab] (
    [id] [int] NOT NULL ,
    [qian] [numeric](8, 2) NOT NULL ,
    [kh] [int] NOT NULL 
    ) ON [PRIMARY]
    GO我也是delphi2009没有发现问题。
    我的是update3测试版的。
      

  2.   


    取消 用参数     CommandText:=sqlstr; 
          tmpCommand.Execute(i,vParam); 直接一次写SQL试下。
    还有2007下,那个可以尝试定期发送一个信息让他不要睡觉。呵呵。没什么好办法
      

  3.   


    问题是我整个项目的代码都是这样,难道要我全改了吗??不想做人了2007那个socket 我有定时30秒调用服务器的一个方法的。。
      

  4.   

    问题解决 果然是delphi2009版本的问题装个update3就解决了
    下载地址 
    ftp://uploads:[email protected]/lsuper_CodeGear.Delphi.2009.RTM.Inc.Update4.v12.0.3300.19037.Lite.v2.3.rar