RSS订阅 | 匿名投稿
您的位置:网站首页 > 数据库 > 正文

delphi ADO 动态建立.mdb数据库,表

作者:admin 来源:未知 日期:2010/4/29 10:58:46 人气: 标签:

ADO 动态建立.mdb数据库,表

procedure Tproject.BitBtn1Click(Sender: TObject);
var
CreateAccess:OleVariant;
DataBaseName:ansiString;
ConnectStr:ansistring;
TdeForm:TTdeForm;
begin
SaveDialog1.Title:='保存项目文件';
SaveDialog1.FileName:=ProjectNamesx;
if not SaveDialog1.Execute then
begin
close;
exit;
end else
begin
DataBaseName:=SaveDialog1.FileName;
ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+'.mdb;';
CreateAccess:=CreateOleObject('ADOX.Catalog');
CreateAccess.Create(ConnectStr);
with ProjectDatamodule do
begin
try
ProjectConnection.ConnectionString:=ConnectStr+'Persist Security Info=true';
ProjectConnection.Connected:=true;
CreateProjectTable();//创建项目信息表
CreateYssTable();//创建项目预算表
createystable();//创建预算表(临时)
CreateGcdjb();// 创建工程单价表
CreateDeclk();//创建定额材料库
CreateStaffTable();//创建材料名细库
CreateGcqfTable();//创建工程取费表
CreateGcdj_lsTable;//创建工程单价表(临时)
CreatelsYsTable;//创建预算书
HasProjectOpened:=true;
end;
end;
end;
//DataModule
interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB;

type
TProjectDataModule = class(TDataModule)
Projectconnection: TADOConnection;
CreateTableQuery: TADOQuery;
qfQuery: TADOQuery;
qfSource: TDataSource;
properQuery: TADOQuery;
ProperSource: TDataSource;
yssadoquery: TADOQuery;
clzhkADOQuery: TADOQuery;
clzhk1query: TADOQuery;
yssquery7: TADOQuery;
clzhkquery: TADOQuery;
yssquery6: TADOQuery;
Yssquery8: TADOQuery;
yssquery: TADOQuery;
yssquery2: TADOQuery;
yssquery3: TADOQuery;
qfquery1: TADOQuery;
DataSource1_1: TDataSource;
clzhkquery_1: TADOQuery;
qfADOQuery: TADOQuery;
jsxmglADOQuery: TADOQuery;
gcqfADOQuery: TADOQuery;
qfclADOQuery: TADOQuery;
clzhkquery_2: TADOQuery;
yssquery2_1: TADOQuery;
gcqfkquery_1: TADOQuery;
zcquery: TADOQuery;
ysadoquery: TADOQuery;
gcsmQuery: TADOQuery;
clmxADOQuery: TADOQuery;
cldjADOQuery: TADOQuery;
clmxDataSource: TDataSource;
cldjtjADOQuery: TADOQuery;
cldjDataSource: TDataSource;
cldjbadoquery: TADOQuery;
dclsaveadoquery: TADOQuery;
fyxzquery: TADOQuery;
bzquery: TADOQuery;
private
{ Private declarations }
public
procedure CreateProjectTable;//创建项目信息表
procedure CreateYssTable;//创建项目预算书
procedure createystable;//创建预算
procedure CreateStaffTable;//创建材料明细表
procedure CreateGcdjb;//工程单价
Procedure CreateDeclk;//定额材料
Procedure CreateGcqfTable;//工程取费
procedure CreateGcdj_lsTable; //创建工程单价表(临时)
procedure CreatelsYsTable;//创建临时预算
function getpy(txt:string):string;
{ Public declarations }
end;
var
ProjectDataModule: TProjectDataModule;

implementation

uses tdeUnit;

{$R *.DFM}
procedure TProjectDataModule.CreateGcdj_lsTable; //创建工程单价表(临时)
begin
with CreateTablequery do
begin
close;
sql.Clear ;
sql.Add('Create Table gcdj_ls(xh char(4) null,demc char(50) null,debh char(50) null,dedw char(10) null,glmc char(20) null,dw char(4) null,sl char(4) null,dj char(10) null,fj char(10) null)');
execsql;
end;
end;

procedure TProjectDataModule.CreateProjectTable();
begin
with ProjectDataModule do
begin
//创建项目信息表
CreateTableQuery.Sql.Clear;
CreateTableQuery.Sql.Text:='CREATE TABLE T_jsxmgl (jsxmmc char(100),qylb char(12),qymc char(100),gclb char(12),gcszd char(100),username char(50),passwd char(50),company char(20),bz text)';
CreateTableQuery.execsql;
end;
end;
procedure TProjectDataModule.CreateYssTable();//创建项目预算书
begin
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;
end;
procedure TProjectDataModule.CreateYsTable();//创建项目预算书
begin
with ProjectDataModule.CreateTableQuery do
begin
close;
SQL.Clear;
Sql.Add('CREATE TABLE 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;
end;

procedure TProjectDataModule.CreateStaffTable();//创建材料明细表
begin
with CreateTableQuery do
begin
close;
sql.Clear ;
sql.Add('Create Table T_clmxk(xh int,clbm char(6),clmc char(100),Dw char(20),');
sql.Add('Dedj numeric(8,3),zcbz char(4),sl numeric(8,3),');
sql.Add('Cdhtydd char(100),ysgj char(50),yj int,ysdj numeric(8,3),xs Numeric(8,3),yf Numeric(8,3))');
execsql;
end;
end;

procedure TProjectDataModule.CreatelsYsTable();//创建预算书
begin
with ProjectDataModule.CreateTableQuery do
begin
close;
SQL.Clear;
sql.Add('Create Table yss_ls(xh char(4) null,demc char(50) null,sl char(10) null,dw char(10) null,dj char(10) null,hj char(10) null)');
CreateTableQuery.execsql;
end;
end;
procedure TProjectDataModule.CreateGcqfTable();
begin
with CreateTablequery do
begin
close;
sql.Clear ;
sql.Add('Create Table T_gcqfb(xh int ,Mc char(50),Dh char(4),Fldh char(4),qfjc char(20),Ss char(100),Fl Numeric(8,3),Jg Numeric(8,3))');
execsql;
end;
end;

procedure TProjectDataModule.CreateDeclk;
begin
with CreateTablequery do
begin
close;
sql.Clear ;
sql.Add('Create Table T_declk(xh int ,debh char(10),clzhbz char(5),clbm char(6),clmc char(100),dw char(20),cdhckj numeric(8,3),');
sql.Add ('zcbz char(4),sl numeric(8,3),cdhtydd char(50),ysgj char(10),xs numeric(8,3),yf numeric(8,3),gqf numeric(8,3),zxf numeric(8,3),cgf numeric(8,3),ysjg numeric(8,3))');
execsql;
end;
end;

procedure TProjectDataModule.CreateGcdjb;
begin
with CreateTablequery do
begin
close;
sql.Clear ;
sql.Add('Create Table gcdj(xh int , debh char(50),glmc char(20),dw char(4),sl char(4),dj char(100),fj numeric(8,3))');
execsql;
end;
end;
end.

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: