一尘不染

德尔福(Delphi)错误:地址xxxxxxxx违反了访问权限。读取地址yyyyyyy'',在AdoQuery.SQL.Text:='''

sql

“在地址xxxxxxxx的访问冲突。读取了地址yyyyyyyy”

在这个项目上,我有200多个类似的程序,但是只有此程序会出错(仅Windows XP)。

程序比有错误:

Procedure TfMain.CreateNewDocument(p_money_direction,p_status,p_base:integer);
begin
  With fMain.ADOTemp  do
  Begin
    SQL.Clear;
    SQL.Text:='INSERT INTO documents '+
              '(document_date,fk_id_status,money_direction,'+
              'paid,addition,saving,fk_id_base,fk_id_user)'+
              'VALUES '+
              '(CONVERT(DATE,:pdocument_date,103),:pfk_id_status,'+
              ':pmoney_direction,0,0,0,:pfk_id_base,:pfk_id_user)';
    Parameters.ParamByName('pdocument_date').Value:=Date;
    Parameters.ParamByName('pfk_id_status').Value:=p_status;
    Parameters.ParamByName('pmoney_direction').Value:=p_money_direction;
    Parameters.ParamByName('pfk_id_base').Value:=p_base;
    Parameters.ParamByName('pfk_id_user').Value:=fMain.ApplicationVariablers.user_id;
    ExecSQL;
  End;
end;

错误:

    SQL.Text:='INSERT INTO documents '+
              '(document_date,fk_id_status,money_direction,'+
              'paid,addition,saving,fk_id_base,fk_id_user)'+
              'VALUES '+
              '(CONVERT(DATE,:pdocument_date,103),:pfk_id_status,'+
              ':pmoney_direction,0,0,0,:pfk_id_base,:pfk_id_user)';

调试过程中,第1907行出现错误:

打印屏幕


阅读 186

收藏
2021-05-16

共1个答案

一尘不染

我这样解决问题

Procedure TfMain.CreateNewDocument(p_money_direction,p_id_status,p_id_base:integer);
Var
  ADOTemp:TAdoQuery;
begin
  ADOTemp:=TADOQuery.Create(nil);
  ADOTemp.Connection:=fMain.ADOConnection;

  With ADOTemp  do
  Begin
    SQL.Clear;
      SQL.Add('INSERT INTO documents');
      SQL.Add('(document_date,fk_id_status,money_direction,');
      SQL.Add('paid,addition,saving,fk_id_base,fk_id_user)');
      SQL.Add('VALUES ');
      SQL.Add('(CONVERT(DATE,GETDATE(),103),:pfk_id_status,:pmoney_direction,');
      SQL.Add('0,0,0,'+IntToStr(p_id_base)+',:pfk_id_user)');

    Parameters.ParamByName('pfk_id_status').Value:=p_id_status;
    Parameters.ParamByName('pmoney_direction').Value:=p_money_direction;
    //Parameters.ParamByName('p').Value:=p_id_base;
    Parameters.ParamByName('pfk_id_user').Value:=fMain.ApplicationVariablers.user_id;
    ExecSQL;
  End;
end;

我删除了 Parameters.ParamByName(’p’)。Value:= p_id_base; 它奏效了

http://oi43.tinypic.com/dvotxx.jpg

但这不是很好的孤独感

2021-05-16