procedure TForm1.SetupTable(sender:tobject);
Var
adocon1:TADOConnection;
strSQL:string;
Const
SConnectionString= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'+'Jet OLEDB:Database Password=%s;';
begin
adocon1:=TADOConnection.Create(self);
adocon1.ConnectionString:=format(SConnectionString,[ExtractFilePath(application.ExeName)+'F:\zhlihui\数据库设计\bellfur\db1.mdb','']);
strsql:='Create table foldersname('+'folderID counter PRIMARY KEY,'+'二月 char(20),'+'三月 char(20),'+'四月 char(20),'+'五月 char(20),'+'六月 char(20),'+'七月 char(20),'+'八月 char(20),'+'九月 char(20),'+'十月 char(20),'+'十一月 char(20))';
adocon1.Execute(strsql);
//表foldersname建立
adocon1.close;
adocon1.free;
end;
我第一次在delphi里动态创建access表,上面程序运行没出错,但是数据库里并没有新建这个表,我想知道是什么问题。如果问题问的太傻,请别见笑。

解决方案 »

  1.   

    procedure TForm1.SetupTable(sender:tobject);
    Var
    adocon1:TADOConnection;
    strSQL:string;
    Const
    SConnectionString= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'+'Jet OLEDB:Database Password=%s;';
    begin
    adocon1:=TADOConnection.Create(self);
    adocon1.ConnectionString:=format(SConnectionString,[ExtractFilePath(application.ExeName)+'F:\zhlihui\数据库设计\bellfur\db1.mdb','']);
    adocon1.Connected:=true;//先连接
    strsql:='Create table foldersname('+'folderID counter PRIMARY KEY,'+'二月 char(20),'+'三月 char(20),'+'四月 char(20),'+'五月 char(20),'+'六月 char(20),'+'七月 char(20),'+'八月 char(20),'+'九月 char(20),'+'十月 char(20),'+'十一月 char(20))';
    adocon1.Execute(strsql);
    //表foldersname建立
    adocon1.Connected:=false;//断开连接
    adocon1.free;
      

  2.   

    1.没连接2.ExtractFilePath(application.ExeName)+'F:\zhlihui\数据库设计\bellfur\db1.mdb
    你不觉得有问题吗?
      

  3.   

    Var
    adocon1:TADOConnection;
    strSQL:string;
    Const
    SConnectionString= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'+'Jet OLEDB:Database Password=%s;';
    begin
    adocon1:=TADOConnection.Create(self);
    adocon1.ConnectionString:=format(SConnectionString,[ExtractFilePath(application.ExeName)+'db1.mdb','']);
    strsql:='Create table foldersname('+'folderID counter PRIMARY KEY,'+'二月 char(20),'+'三月 char(20),'+'四月 char(20),'+'五月 char(20),'+'六月 char(20),'+'七月 char(20),'+'八月 char(20),'+'九月 char(20),'+'十月 char(20),'+'十一月 char(20))';
    adocon1.Execute(strsql);
    //表foldersname建立
    adocon1.close;
    adocon1.free;测试通过。