执行代码如下:
procedure TPCodemainfrm.ViewPCodeIDClick(Sender: TObject);
begin ComboBox1.Text:='';
 ReportView.Enabled:=True; cxGrid1DBTableView1.DataController.DataSource:=dms.datasPCodeID;    cxGrid1DBTableView1ident.Visible:=True;
    cxGrid1DBTableView1a1.Visible:=True;
    cxGrid1DBTableView1a2.Visible:=True;
    cxGrid1DBTableView1a3.Visible:=True;    cxGrid1DBTableView1P_CodeID.Visible:=false;
    cxGrid1DBTableView1ColorID.Visible:=false;
    cxGrid1DBTableView1Weigth.Visible:=false;    cxGrid1DBTableView1ColorID1.Visible:=false;
    cxGrid1DBTableView1Chinesename.Visible:=false;
    cxGrid1DBTableView1Englishname.Visible:=false;//dms.AdoPCodeID的DataSource是指向dms.datasPCodeID
//采用了cxGrid第三方组件 with dms.AdoPCodeID do
   begin
    Close;
    SQL.Clear;
    SQL.LoadFromFile(WPath+'\SQL\SearchRecords.sql');
    Open;
   end;end;老是出现
“Project XXX.EXE raised exception class EoleException With Message '第一行:'?'附近有语法错误。'.”的问题。
我检查了SQL查询语句,在查询分析器里是正常的,没有问题,我把查询语句放到ADOQuery的WideString里也是正常显示!就是用一个按钮来执行的话就会出现那个问题!
我的D2006是正版的!在D7里是没有问题的!会不会是D2006的问题?请高手不吝赐教!
谢谢!

解决方案 »

  1.   

    我检查了SQL查询语句,在查询分析器里是正常的,没有问题,我把查询语句放到ADOQuery的WideString里也是正常显示!把语句贴出来看看。在查询分析器里能执行的,在delphi中如果参数没有设置对,一样不能执行。
      

  2.   

    create table #temptable
    (
    ident int,
    a1 varchar(10),
    a2 varchar(10),
    a3 varchar(10),
      a4 varchar(10),
    a5 varchar(10),
    )declare @t1 integer
    declare @t2 integer
    declare @t3 integer
    declare @t4 integer
    declare @t5 integerset @t1 = 1
    set @t2 = 1
    set @t3 = 1
    set @t4 = 1
    set @t5 = 1declare @str varchar(50)
    declare @colname varchar(50)
    declare A_Cursor cursor for select DISTINCT P_CodeID from PCodeColores order by P_CodeID
    open A_Cursorwhile ( 1 > 0)
    begin
       fetch next from A_Cursor into @str
       if ( @@FETCH_STATUS <> 0 ) break
       --插入操作
       if (substring(@str,1,3) = 'p11') 
       begin
         print('@1')
         if exists( select a1 from #temptable where ident = @t1 )  
         begin
    update #temptable
            set a1 = @str
            where ident = @t1
         end
         else
         begin
            insert into #temptable (ident,a1) values (@t1,@str)
         end
         set @t1 = @t1+1
       end   if (substring(@str,1,3) = 'p12') 
       begin
         print('@2')
         if exists( select a2 from #temptable where ident = @t2 )  
         begin
    update #temptable
            set a2 = @str
            where ident = @t2
         end
         else
         begin
            insert into #temptable (ident,a2) values (@t2,@str)
         end
         set @t2 = @t2+1
       end   if (substring(@str,1,3) = 'p13') 
       begin
         print('@3')
         if exists( select a3 from #temptable where ident = @t3 )  
         begin
    update #temptable
            set a3 = @str
            where ident = @t3
         end
         else
         begin
            insert into #temptable (ident,a3) values (@t3,@str)
         end
         set @t3 = @t3+1
       end   if (substring(@str,1,3) = 'p14') 
       begin
         print('@4')
         if exists( select a4 from #temptable where ident = @t4 )  
         begin
    update #temptable
            set a4 = @str
            where ident = @t4
         end     else
         begin
            insert into #temptable (ident,a4) values (@t4,@str)
         end
         set @t4 = @t4+1
       end   if (substring(@str,1,3) = 'p15') 
       begin
         print('@5')
         if exists( select a5 from #temptable where ident = @t5 )  
         begin
    update #temptable
            set a5 = @str
            where ident = @t5
         end
         else
         begin
            insert into #temptable (ident,a5) values (@t5,@str)
         end
         set @t5 = @t5+1
       end    print(@str)end
    close A_Cursor
    deallocate A_Cursorselect * from #temptabledrop table #temptable没有使用外部参数!
    在D7里是没有问题的!谢谢!
      

  3.   

    create table #temptable
    (
    ident int,
    a1 varchar(10)
    )declare @t1 integerset @t1 = 1declare @str varchar(50)
    declare @colname varchar(50)
    declare A_Cursor cursor for select DISTINCT P_CodeID from PCodeColores order by P_CodeID
    open A_Cursorwhile ( 1 > 0)
    begin
       fetch next from A_Cursor into @str
       if ( @@FETCH_STATUS <> 0 ) break
       --插入操作
       if (substring(@str,1,3) = 'p11') 
       begin
         print('@1')
         if exists( select a1 from #temptable where ident = @t1 )  
         begin
    update #temptable
            set a1 = @str
            where ident = @t1
         end
         else
         begin
            insert into #temptable (ident,a1) values (@t1,@str)
         end
         set @t1 = @t1+1
       end    print(@str)end
    close A_Cursor
    deallocate A_Cursorselect * from #temptabledrop table #temptable没有使用外部参数!
    在D7里是没有问题的!谢谢!
      

  4.   

    晕死,干么不整成存储过程啊,你这样执行这么多sql语句,光发送到服务器端,就要花好多时间啊。
      

  5.   

    数据不是很多
    所以速度还是可以的!
    一般一秒就可以了!
    呵呵~~~~~~~~~~
    To  erhan()
    你觉得存储过程怎么写比较好呢?
    请赐教啦!
    谢谢!
      

  6.   

    基本上跟你的SearchRecords.sql的内容是一样的哈。
      

  7.   

    你现在的服务器与客户端都布署在局域网里吧,如果通过internet就不中了哈。
      

  8.   

    用程序Show 出来看看。
    你的SQL文件是不是Ansi的格式,还是Utf-8还是Unicode,如果不是Ansi格式的你要转换成Ansi格式的,否则可能会出现这种错误。
      

  9.   

    create table #temptable
    (
    ident int,
    a1 varchar(10),
    a2 varchar(10),
    a3 varchar(10),
     a4 varchar(10),
    a5 varchar(10),
    )
    a5这一行后面是不是多了个逗号呢?这句话在sql下面的确是可以执行的
      

  10.   

    实在是不知所以然,不行还是按我方法改成存储过程吧
    CREATE PROCEDURE SearchRecords
    AS
            --以下加入你的代码
    存储过程是在服务器上加的哈,应该知道的吧delphi中的调用方法
    adoquery1.sql.text := 'exec SearchRecords'
    adoquery1.ExecSQL;
      

  11.   

    你那段sql是有结果集返回的吧,那就应该是
    adoquery1.sql.text := 'exec SearchRecords';
    adoquery1.open;