大哥们:
   
   我放置了一个ADOConnecion控件
  设好属性后,测试连接,他说连接成功?
  又放置了一个ADOQuery控件,他的Connection属性设置为DataModule2.ADOConnection1
  下面是打开的代码,调试时一执行到open就说miss connection or connection string:
  procedure Tmainform.setrecordarray(tablename,KP:string;tixing:integer);
var
i:integer;
value:integer;
begin
with ADOQuery1 do
 begin
  close;
  with sql do
   begin
    clear;
    add('select ID from '+tablename);    add('where Knowledgepoint= '+KP);
    
   end;
   open;
  end;
  ADOQuery1.first;
  i:=1;
  while not(ADOQuery1.eof) do
   begin
    value:=ADOQuery1.fieldbyname('ID').value;
    recordarray[tixing,strtoint(KP),i]:=value;
    ADOQuery1.next;
    i:=i+1;
   end;
   recordarray[tixing,strtoint(KP),i]:=-1;
end;

解决方案 »

  1.   

    DataModule2有没有在这段代码执行前创建?是否Connected=True?
      

  2.   

    我哪个ADOConnection1就放在DataModule2上的呀?
    ADOConnection1的Connected早就设置成true了!
      

  3.   

    with ADOQuery1 do
     begin
      close;
    //加下面一段代码高度一下
      if not Assigned(DataModule2) then
      begin
        ShowMessage('DataModule2 not create');
        Exit;
      end;
    //
      with sql do
       begin
        clear;
        add('select ID from '+tablename);    add('where Knowledgepoint= '+KP);
        
       end;
      

  4.   

    大哥:
       是没有创建DataModule2
      但我在file /new菜单里的data Module创建的呀
      他是一个unit1单元
      我在要用到他的单元中,已经use了!
    该怎么办?
      

  5.   

    你可能是创建了, 但是在Application.CreateForm(mainForm,TMainForm)一句后面创建的?
      

  6.   

    现在我把Application.CreateForm(TDataModule1, DataModule1);
    放在Application.CreateForm(mainForm,TMainForm)
    前面了,但不能open呀?
    即使我不用DataModule
    把ADOConnection和ADOQuery同时放在mainForm上
    也不能open呀?
    还是说没有connection or connection strings
      

  7.   

    不可能的。可能是你的ADOConnecion有问题你确认可以连接上吗?
      

  8.   

    你可以不用ADOConnecion,直接给你的ADOQUERY connectionstring 先调试一下试试
      

  9.   

    你把你的CONNECTION STRING COPY 出来看看
      

  10.   

    add(' where Knowledgepoint= '+KP)//where前面加个空格