在D6+Access2000中怎么样创建表?(50分)

  • 主题发起人 Gingerzy
  • 开始时间
G

Gingerzy

Unregistered / Unconfirmed
GUEST, unregistred user!
在D6+Access2000中怎么样创建表?
 
我是装了个OFFICE XP,用ACCESS来创建比较直观。
 
用ADO连接数据库,然后用SQL语句实现。
Create Table Tab_Name......
 
to ckylixj:
能祥细点吗?
 
procedure TDMpara.CreateDescTable(chartype: string; isFillInData: boolean =
False);
begin
with tblLocalDESC do
begin
Active := false;
TableName := chartype + 'DESC'; {表格名}
TableType := ttParadox; {数据库类型}
with FieldDefs do
begin {增加字段}
Clear;
Add('Title', ftString, 30, true); {监控名 String(30)}
Add('Chars', ftstring, 200, False); {监控描述 String(30)}
end;
{ with IndexDefs do begin //增加索引
Clear; //按书号字段建立主索引
Add('SHSY','SH',[ixPrimary,ixUnique]);
end;
}
CreateTable;
end;
if isFillInData then
FillInDescTableData();
end;
 
创建access表,如何做?
 
{******************************************************************************}
{函数名称:CreateDb 新建数据 }
{入口参数: }
{版权所有:}
{创建时间:}
{最后修改时间: }
{修改人:Email: lightwdy@163.com }
{******************************************************************************}

procedure CreateDb(DbName: string;strSql:Tstrings);
var
Dbnew:OleVariant;
adoqTmp:TADOQuery;
intCyc:integer;
begin
if FileExists(DbName) then
begin
MessageBox(Application.Handle,PChar('数据库:' + DbName+'已经存在!'),
CommonTitle,CommonFlag);
exit;
end;
//建库
dbnew:=CreateOleObject('ADOX.Catalog');
dbnew.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DbName);
//建表
adoqTmp:=TADOQuery.Create(nil);
adoqTmp.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+dbname+';Persist Security Info=False';
for intCyc:=0 to strsql.Count-1 do
begin
with adoqTmp do
begin
Close;
SQL.Text:=strSql[intcyc];
ExecSQL;
end;
end;
MessageBox(Application.Handle,PChar('数据库:' + DbName+'创建完成'),
CommonTitle,CommonFlag);
end;

参数举例:
strSql:tstrings;

strsql:=TStringList.Create;
//创建单位信息表
//单位信息表:CompanyInfo
//lngCompanyId 单位ID 自增 整型
//strCompanyCode 单位编码 字符性 4
//strCompanyName 单位名称 字符型 40
//strCompanyAddress 单位地址 字符型 60
//strCompanyTel 单位电话 字符型 40
//strIndustryCode 产业编码 字符型 40 'new
strSql.Add(' CREATE TABLE CompanyInfo ( '+
' lngCompanyId int IDENTITY (1, 1) PRIMARY KEY NOT NULL , '+
' strCompanyCode char(20) NOT NULL , '+
' strCompanyName char(40) NOT NULL , '+
' strIndustryCode char(40) NOT NULL , '+
' strCompanyAddress char(60) NULL , '+
' strCompanyTel char(40) NULL '+
' )');
//创建主键与索引
strsql.Add('Create UNIQUE Index IDIndex ON CompanyInfo (lngCompanyId)');
strsql.Add('Create Index IndustryCodeIndex ON CompanyInfo (strIndustryCode)');
再调用上述函数即可
 
帖段代码自己看吧
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var
CreateAccess:OleVariant;
begin
CreateAccess:=CreateOleObject('ADOX.Catalog');
CreateAccess.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:/temp/Aceco.mdb;Jet OLEDB:Database Password=55629');

end;


end.
 
请问各位大虾,要产生一个带密码的库怎么做,谢谢了
 
多人接受答案了。
 
顶部