📄 lbldba.pas
字号:
unit LblDBA;
interface
uses Classes, SysUtils, DB, ADODB, Dialogs, DBTables, Comobj, ActiveX;
function CreateDB(DBName :string;PWD:String;IsTbl:Boolean):Boolean;
function CreateInitDBTable(DBName :string;PWD:string):Boolean;
function CreateDBTable(DBName :string;PWD:string;CreateDBSQL:TStrings):Boolean;
implementation
{***************************************************************************}
{函数名称:CreateDb 新建数据库 }
{入口参数: }
{修 改 人: xjl Email:xiongjianlong@tom.com }
{***************************************************************************}
function CreateDB(DBName:string;PWD:string;IsTbl:Boolean):Boolean;
var
DbNew:OleVariant;
ss : String;
begin
Result := False;
if FileExists(DBName) then
begin
Exit;
end;
ss:= 'Provider=Microsoft.Jet.OLEDB.4.0;'
+' Data Source='+DBName+';'
+' Jet OLEDB:Database Password ='+ Pwd;
//建库
try
DbNew:=CreateOleObject('ADOX.Catalog');
DbNew.Create(ss);
except
Exit;
end;
Result := True;
If IsTbl then
Result := CreateInitDBTable(DBName,PWD)
end;
function CreateInitDBTable(DBName :string;PWD:string):Boolean;
var
CreateDBSQL : TStringList;
begin
CreateDBSQL:=TStringList.Create;
// 创建'Label'
CreateDBSQL.Add('Create Table MLabel('
+' LblID varchar(14) WITH COMP not null Primary Key,'
+' LblName varchar(20) WITH COMP not null,'
+' Mem1 varchar(20) WITH COMP null)');
//创建索引
CreateDBSQL.Add('Create UNIQUE Index LabelID ON MLabel(LblID)');
CreateDBSQL.add('Create UNIQUE Index LabelName ON MLabel(LblName)');
//创建标签与数据表对应关系表
//创建数据表与标签对应关系表
CreateDBSQL.Add(' Create Table MLblFld('
+' LblID varchar(14) WITH COMP not Null ,'
+' FldID int IDENTITY(1,1) not null Primary Key,'
+' FldName varchar(20) WITH COMP not null,'
+' mem1 varchar(20) WITH COMP null)');
//创建索引
CreateDBSQL.Add(' Create Index LblDstID ON MLblFld(LblID)');
// 'LblField'
// 'SysUser'
CreateDBSQL.Add(' CREATE TABLE SysUser ('
+' UserID int identity(1,1) not null primary key,'
+' UserName varchar(30) WITH COMP not null,'
+' Pwd varchar(12) WITH COMP null,'
+' Mem1 varchar(50) WITH COMP null'
+' )');
//创建主键与索引
CreateDBSQL.Add('Create UNIQUE Index SysUserUID ON SysUser(UserID)');
CreateDBSQL.Add(' Insert into SysUser(UserName,Pwd,Mem1) values("Admin","888888","系统创建用户") ');
If CreateDBTable(DBName,PWD,CreateDBSQL) then
Result := True
else
Result := False;
end;
function CreateDBTable(DBName :string;PWD:string;CreateDBSQL:TStrings):Boolean;
var
ss : string;
AdoQryCreateDB:TADOQuery;
intCyc :integer;
begin
Result := False;
ss:= 'Provider=Microsoft.Jet.OLEDB.4.0;'
+' Data Source='+DBName+';'
+' Jet OLEDB:Database Password ='+ PWD;
//建表
AdoQryCreateDB := TADOQuery.Create(nil);
AdoQryCreateDB.ConnectionString := ss ;
for intCyc:=0 to CreateDBSQL.Count-1 do
begin
with AdoQryCreateDB do
begin
Close;
SQL.Text:=CreateDBSQL[intcyc];
try
// ShowMessage(SQL.Text);
ExecSQL;
Result := True;
except
Exit;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -