大虾们:
    我想在程序里用Table控件给一个已存在的db文件加一个字段(db文件由程序通过路径访问),最好有代码!
谢谢

解决方案 »

  1.   

    with dm.qmain do begin
          close;
          sql.Clear;
          sql.Add('alter table monthlist add T'+copy(yearmon,1,4)+copy(yearmon,6,2)+' money');
          ExecSQL;//qmain是Tquery
      

  2.   

    大哥,我是这样写的,我的程序运行后原来的字段没了,帮我改一下!  
      outdbloc:=edit3.Text;
      outdbname:=edit4.Text;
     with outtable do begin
        databasename:=outdbloc;
        tablename:=outdbname;
        tabletype:=ttparadox;
        with fielddefs do begin
             add('Receive',ftinteger,0,true);
             add('Send',ftinteger,0,true);
             add('Count',ftinteger,0,true);
        end; //of while  field
        createtable;
      end;//of while ttable.create
      

  3.   

    outdbloc:=edit3.Text;
      outdbname:=edit4.Text;
     with outtable do begin
        Active := False;
        databasename:=outdbloc;
        tablename:=outdbname;
        tabletype:=ttparadox;
          with AddFieldDef do begin
            Name := 'Receive';
            DataType := ftInteger;
            Required := True;
          end;
          with AddFieldDef do begin
            Name := 'Send';
            DataType := ftInteger;
            Required := True;
          end;
          with AddFieldDef do begin
            Name := 'Count';
            DataType := ftInteger;
            Required := True;
          end;
        createtable;
      end;//of while ttable.create
      

  4.   

    大哥,有错误:
    [Error] testp.pas(44): Undeclared identifier: 'AddFieldDef'
    [Error] testp.pas(46): Undeclared identifier: 'DataType'
    [Error] testp.pas(47): Undeclared identifier: 'Required'
    该怎么办?
      

  5.   

    用一个query控件就行了
        form1.query1.SQL.clear;
        form1.query1.SQL.add('alter table ');
        form1.query1.SQL.add('c:\myfile.db');
        form1.query1.SQL.add('add ');
        form1.query1.SQL.add('myfield char(10) ');
        form1.query1.execsql;
      

  6.   

    大哥:
       query 跟那个table怎么连起来呀?
     你能不能根据我上面的代码,给我改一下!
    谢谢!
      

  7.   

    query.sql.add('alter 表名称 add 要增加的字段名 varchar(60) ')
    说明:varchar 是增加字符型,60是长度。
      

  8.   

    大哥:
       还是加不进去呀?
       我是这样写的
       var
    outtableloc:string;
    outtablename:string;
    begin
    outtableloc:=edit1.Text;
    outtablename:=edit2.Text;
    query1.SQL.Add('alter outtable add receive varchar(6) ');
    其中加了Table控件,控件名为outtable
    加了query 控件,属性为默认的(没该)
      

  9.   

    大哥:
      用query控件好像不行呀!
      我是这样写的
    form1.query1.SQL.clear;
        form1.query1.SQL.add('alter table ');
        form1.query1.SQL.add('f:\cj451_117.DB');
        form1.query1.SQL.add('add ');
        form1.query1.SQL.add('myfield char(10) ');
        form1.query1.execsql;
    执行后出现
    raise exception class EDatabaseError with  message 'Query1:Field 'cj451_117.DB' is of an unknow type'
    process stoped.
      

  10.   

    大哥:
        还是不行呀!他说‘table does not exist‘
       该怎么办?是不是query属性要设置呀!还是?能不能给我发一个工程过来?db文件名用edit控件输入.email:[email protected],源码如下:
        form1.query1.SQL.clear;
        form1.query1.SQL.add('alter table ');
        form1.query1.SQL.add('"'+'f:\cj451_117.DB'+'"');//这里前后要加双引号我试了,没有错了
        form1.query1.SQL.add('add ');
        form1.query1.SQL.add('myfield char(10) ');
        form1.query1.execsql;
        showmessage('ok');