if edit1.text<>emptystr then
begin
deptname:=edit1.text;
  with qrydeptadd do begin
      close;
      sql.clear;
      sql.add('select * from department');
      sql.add('where deptname=:deptname');
      open;
  end;
   
  if query1.isemptyed then 
            with qrydeptadd do 
               begin
                   close;
                   sql.clear;
                   sql.add('insert into department(deptname) values='''+edit1.text+''' ');
             execsql;
            end;

解决方案 »

  1.   

    我觉得子这样好像也可以
    if query1.isemptyed then 
                with qrydeptadd do 
                   begin
                       close;
                       sql.clear;
                       sql.add('insert into department(deptname) values='+quotedstr(edit1.text));
                 execsql;
                end;
      

  2.   

    其实可以做一个过程
    procedure query_pro(sqlstring:string;sql-control:integer);
    begin
        with query1 do
         begin
          close;
          sql.clear;      
          sql.add(sqlstring);
          
     //用数字 1 代表一般查询 使用 OPEN,用数字 0 代表特殊操作,使用exesql语句
          if sql-control=1 then open
             else if sql-control=0 then exesql;
         end;
    end;然后在程序的其他地方就可以这样调用了
        query_pro('select * from lll',1);
      

  3.   

    if query1.isemptyed then          
     with qrydeptadd do               
         begin                  
          close;                   
          sql.clear;               
          sql.add('insert into department(deptname) values='''+edit1.text+''' ');            
          execsql;           
     end;然后就出现下面的错误
    真是不知道怎么回事~
    project MISair.exe raised exception class EDBEngineError with
    message 'Invalid use of keyword
    Token:='edit1'
    Line1 Number: '1' . Process stopped. Use step or Run to continue.
    表:department
    deptid 自动增量
    deptname