我想用TADOQuery变量作临时的query控件,但它总是报错。代码如下:
function getid(table:string;field:string):integer;
var
  max,min:integer;
  q,q1:TADOQuery;
  conn:widestring;
begin
    conn:='Provider=SQLOLEDB.1;Password=8107;Persist Security Info=True;User ID=zwl;Initial Catalog=library;Data Source=HEAVEN';
    q.Close;    -------出错处
    q.ConnectionString:=conn;
    q.Open;
    q1.close;
    q1.ConnectionString:=conn;
    q1.Open;
    q.first;
    if not q.eof then
    begin
      q.last;
      if q.Recordset.RecordCount=q[field]+1 then
        getid:=q[field]+1
      else
      begin
        max:=q[field];
        min:=0;
        with q1 do
        begin
          close;
          sql.Clear;
          sql.Add('select * from '+table+' where '+field+'='+inttostr(min));
          open;
          while ((not eof) and (min<max)) do
          begin
            min:=min+1;
            close;
            sql.Clear;
            sql.Add('select * from '+table+' where '+field+'='+inttostr(min));
            open;
          end;
        end;
        getid:=min;
      end;
    end
    else
      getid:=0;
end;
错误信息:EAccessViolation with message 'Access violation at address 00482078 in module 'Project1.exe'.