with query1 do
begin
  close;
  sql.clear;
  sql.add('create table (ID int NOT NULL,Name varchar(50) NOT NULL));
  ExecSQL;
end;

解决方案 »

  1.   

    CREATE TABLE t(x INT PRIMARY KEY)具体详细情况请查看Sqlserver帮助文件
      

  2.   

    var
     hostname:string;
     begin
    try
           with ADOCommand1 do
             begin
               CommandText:='Create Table '+HostName+'(id Counter not null,Type text(25),TDate datetime,Code text(2),Computer Text(25),Details Text(255),Status text(2))';
               execute;
                 end;
         except
          Raise Exception.Create('创建表出错!');
         end;
      

  3.   

    我同意cgll20(代码最优化)的方案。
      

  4.   

    with ProjectDataModule.CreateTableQuery do
        begin
            close;
            SQL.Clear;
            Sql.Add('CREATE TABLE T_yss (xh int,debh char(10),demc char(150),dw char(30),');
            sql.add('sl numeric(8,3),jj numeric(10,3),jjhj numeric(10,3),');
            sql.add('rgdj numeric(8,3),rghj numeric(10,3),cldj numeric(10,3),');
            sql.add('clhj numeric(8,3),jxdj numeric(10,3),jxhj numeric(10,3),');
            sql.add('gcm char(100),zjbm char(12),clzhbz char(6))');
            CreateTableQuery.execsql;
        end
      

  5.   

    with ProjectDataModule.CreateTableQuery do
        begin
            close;
            SQL.Clear;
            Sql.Add('CREATE TABLE T_yss (xh int,debh char(10),demc char(150),dw char(30),');
            sql.add('sl numeric(8,3),jj numeric(10,3),jjhj numeric(10,3),');
            sql.add('rgdj numeric(8,3),rghj numeric(10,3),cldj numeric(10,3),');
            sql.add('clhj numeric(8,3),jxdj numeric(10,3),jxhj numeric(10,3),');
            sql.add('gcm char(100),zjbm char(12),clzhbz char(6))');
            CreateTableQuery.execsql;
        end
      

  6.   

    解决了的话可以把Demo发到:[email protected]
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, comobj,adox_tlb,Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      Catalog: _Catalog;
      Table: _Table;
      Index : _Index;
      //FKey : _key;
      strCon:string;//定义连接字符串
      yourname:string;
      yourpwd:string;
    begin
        yourname:=trim(edit1.Text);
        yourpwd:=trim(edit2.text);
        Catalog := CoCatalog.Create;
        strCon := 'Provider=Microsoft.Jet.OleDB.4.0;'
        //通过Jet OleDb直接操作Access数据库
        +'Data Source=c:\windows\desktop\'+yourname+'.mdb;'
        //数据库位置
        +'Jet OLEDB:Engine Type=5;'
        //Jet 4.x格式,如为4,则Jet 3.x格式
        +'Locale Identifier=0x0804;'
         //支持简体中文(一定要有)
        +'Jet OLEDB:Database Password='+yourpwd;//修改密码也在此;
        //加入密码
        Catalog.Create(strCon); //建立数据库,如果存在就不必CREATE了
        {建立数据表和索引}
        Catalog.Set_ActiveConnection(strCon);
        //连接到数据库    with Catalog do
        begin //建立数据表
        Table:= CoTable.Create(); //建立Table实例    with Table do
        begin
        Name := 'MyTable1';    //建表 MyTable1
        Table.ParentCatalog := Catalog ;
        Columns.Append('ID',adInteger,8);
        
        Columns.Item['ID'].Properties.Item['AutoIncrement'].Value := true;
        
        Columns.Append('Name',adVarWChar,40);
        Columns.Append('Parent_ID',adInteger,8);
        Columns.Item['Parent_ID'].Properties['Default'].Value := 0;
                                               
        Columns.Append('Sort_ID',adInteger,8);
        Columns.Append('Counter',adInteger,8);
        Columns.Item['Counter'].Properties.Item['Default'].Value := 0;    //数据类型详见MDAC SDK
        Tables.Append(Table);  //建表 MyTable1    Index := CoIndex.Create() as _Index; //建立索引
        with Index do
        begin
        Name:='Idx1';
        PrimaryKey := True ;
        Unique := True;
        Columns.Append('ID',adInteger,8);
        _Release;
        end;
        Table.Indexes.Append(Index,EmptyParam);    Table._Release;
        Table:= CoTable.Create();
        end;           //with table do
        end;           //with catalog doend;end.
      

  8.   

    to luoshumeng(乡村以外):
    恕我愚钝,我试了一下你的代码,发现有很多错误,_catalog和_index改成tcatalog和tindex也不能定义,这是D6中的吗?我用的是D5。能否把你的源代码发一份给我?最好能直接演示。谢谢!
      

  9.   

    to moodboy(奇怪) ,创建数据表的时候要先用ADOConnection1打开数据库
    with ADOquery1 do
    begin
      close;
      sql.clear;
      sql.add('create table (ID int NOT NULL,Name varchar(50) NOT NULL));
      ExecSQL;
    end;
      

  10.   

    to cg1120(代码最优化):
    能否说明白点?谢谢!
      

  11.   

    先要设置ADOCONNECTION1.CONNECTED:=TRUE激活,然后对库表操作,比如增加表格with ADOquery1 do
    begin
      close;
      sql.clear;
      sql.add('create table (ID int NOT NULL,Name varchar(50) NOT NULL));
      ExecSQL;
    end;ADOQUERY1.SQL的内容如果不是SELECT,那就应该调用.EXECSQL方法来执行
      

  12.   

    怎么都是提这段代码,难道不能实际点吗?我的数据库已经建立,现在要做的只是在程序中动态的往库里添加表,表为Access。也许这个问题很简单,但对我来说不懂就是不懂,我也找不到好的资料,还望大家多多指教。大虾们不会是嫌分少吧,如此的话,那还叫什么大虾?