怎样用ADOX创建数据库,数据表和索引?有没有其它简单的方法?

解决方案 »

  1.   

    creat table 
    不就是SQL语句吗
    建议看SQL Server帮助
      

  2.   

    function TForm3.GetType: String;//此函数用的是SQL Server数据库
    begin
      case ComboBox1.ItemIndex of
        0: Result := 'varchar';
        1: Result := 'numeric';
        2: Result := 'datetime';
        3: Result := 'ntext';
      end;
    end;function TForm3.GetQuerStr: String; //  此函数用的是ACCESS数据库
    begin
      case ComboBox1.ItemIndex of
        0: Result := 'Alter table diary add ' + Edit1.Text + ' varchar(' + Edit3.Text + ')' + 'null';
        1: Result := 'alter table diary add ' + Edit1.Text + ' float ' + ' null';
        2: Result := 'alter table diary add ' + Edit1.Text + ' datetime' + 'null';
        3: Result := 'alter table diary add ' + Edit1.Text + ' text ' + 'null';
      end;
      //删除字段的话得先把字段取出 然后用  alter table diary drop column 字段名
    end;
    procedure TForm3.Button1Click(Sender: TObject);
    var
      QuerStr: String;
    begin
      QuerStr := GetQuerStr;
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add(QuerStr);
        try
          ExecSQL;
        except
          ShowMessage('创建字段出错,请重新创建');
          Exit;
        end;