有这样一段程序,其中目的之一是判断SQL语句中的一个字段值是否为‘002’,并给出用户提示信息,但运行时,出现错误信息:Access violation at address 000xxxx
源码如下:
.
.
.
with query1 do
begin
  close;
  sql.clear;
  vstr:='select a.code,b.mpid from db1 a left join db2 b on a.code=b.code'
  sql.add(vstr);
  open;
  first;
  do while not eof do
     begin
       AdoDataSource1.insert;
       AdoDataSource1Code.Value:=Fields[0].Value;
       If Fields[1].value='002' then
          Application.MessageBox('存在002类产品','信息提示',0);
       next;
     end;  
end;
.
.
.

解决方案 »

  1.   

    >>Access violation at address 000xxxx
    一般是數據驅動有問題了, 我覺得!
    如果是找不到數據庫之類, 只會簡單報個錯!
      

  2.   

    你先调试一下咯,看出错位置在哪里?或者把下面部分先注释掉,先看上面部分执行是否通过,然后一步步调试
    with query1 do
    begin
      close;
      sql.clear;
      vstr:='select a.code,b.mpid from db1 a left join db2 b on a.code=b.code'
      sql.add(vstr);
      open;
      first;
    end 先执行
      

  3.   

    If Fields[1].value='002' then
              Application.MessageBox('存在002类产品','信息提示',0);关键是增加了这一句,就出错了。
    如果没这句话,不会有报错,运行正常哦!
      

  4.   

    //数据库连接可能有问题。
    with query1 do
    begin
      close;
      sql.clear;
      vstr:='select a.code,b.mpid from db1 a left join db2 b on a.code=b.code'
      sql.add(vstr);
      open;
      first;
      while not eof do // 原来多了一个do
         begin
           AdoDataSource1.insert;
           AdoDataSource1Code.Value:=Fields[0].Value;
           If Fields[1].value='002' then
              Application.MessageBox('存在002类产品','信息提示',0);
           next;
         end;  
    end;
      

  5.   

    active //打开  do while not eof do //错  a.code,b.mpid  // b.mpid=fields[1]??integer的?
      Fields[1].asstring 试试简单方法:with query1 do
    begin
      close;
      sql.clear;
      vstr:='select a.code,b.mpid from db1 a left join db2 b on a.code=b.code where b.mpid=002'
      sql.add(vstr);
      open;
      if not eof then
         begin
         Application.MessageBox('存在002类产品','信息提示',0);
         end;
      Close;  
    end;
      

  6.   

    对不起
    do while not eof do //存在笔误其实,我在这个循环中,要完成对查询结果的插入到另外一个表的同时,需要检查字段MPID的内容
    如果没这个if语句,程序运行是正常的。
      

  7.   

    斑竹forgot2000,快帮帮手看一看啊!!!
      

  8.   

    If Fields[1].value='002' then改成 If Fields[1].text='002' then
      

  9.   

    语法上,编译都能通过,就是在运行时报出以下错误:
    出现错误信息:Access violation at address 000xxxx
      

  10.   

    If Fields[1].value='002' then
    改成:
    if query1.FieleByName('mpid').asstring='002'
    不知道好不好?