诸位CSDN的大大好!
小弟我有一个问题想请教!
我有一个数据库,数据如下:
id name money .....
0001 张三 1200请问:如何依照现有数据库的数据,创建新的数据库,并更新其中的数据?保存新的数据库以当月为名,如:200601.mdb
下一次打开,如果是在本月,则不新建,如果已经到下个月了,则新建如 200602.mdb 的数据库,并更新所有数据?跪求相关代码,越详细越好!谢谢!
小弟我有一个问题想请教!
我有一个数据库,数据如下:
id name money .....
0001 张三 1200请问:如何依照现有数据库的数据,创建新的数据库,并更新其中的数据?保存新的数据库以当月为名,如:200601.mdb
下一次打开,如果是在本月,则不新建,如果已经到下个月了,则新建如 200602.mdb 的数据库,并更新所有数据?跪求相关代码,越详细越好!谢谢!
解决方案 »
- 15位的整数需要用什么数据类型?
- 判断加班问题?请兄台帮帮小妹……
- 有没有办法在程序窗体隐藏的情况下点击窗体内TWebBrowser控件的指定座标啊?
- QQ自动登陆程序,高手帮忙!
- 用BDE 访问ACCESS!!!问问问!!!!!!
- 请给应届毕业生指条明路?为什么应届毕业生这么难招工作?
- SQL发问!!!
- ADO多线程将ACCESS数据库导入SQL SERVER 中途结束线程,丢失记录的问题,急,在线等.
- 取硬盘序列号,有时一运行就死机
- adodataset1.DeleteRecords的例子??????
- 请问Delphi中如何获得CPU使用率和CPU队列长度?
- $IFDEF DEBUGMSG是什么意思?
http://blog.csdn.net/wudi_1982/archive/2006/05/31/764880.aspx
判断数据库名
再判断一下数据库是否存在,不在就Create DataBaae DataBase_Name
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BaseFrm, Menus, cxLookAndFeelPainters, StdCtrls, cxButtons,
cxControls, cxContainer, cxEdit, cxTextEdit, ExtCtrls,ConstUtils,
PublicUtils;
const
BACKUP = 0; //数据备份
RESTORE = 1; //数据恢复
type
TBackupDBForm = class(TBaseForm)
openDL: TOpenDialog;
cxButton1: TcxButton;
ButDataPath: TcxButton;
edtoldData: TcxTextEdit;
btnClose: TcxButton;
btnLogin: TcxButton;
Bevel: TBevel;
edtNewData: TcxTextEdit;
procedure btnLoginClick(Sender: TObject);
procedure ButDataPathClick(Sender: TObject);
procedure cxButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
//备份与还原状态值
BRConst : integer; //取路径
Dir:string; //显示备份与还原状态
Procedure MainShow; //
Procedure GetDir(path:string;BorR:integer); //取得数据库加系统时间
Function GetmdfName(Path:string):string; // procedure LoadConstBR;
public
{ Public declarations }
end;implementation{$R *.dfm}procedure TBackupDBForm.FormCreate(Sender: TObject);
begin
inherited;
BRConst := StrToInt(GetParam('BackupRestore'));
MainShow;
openDL.Filter := 'Access数据库文件(*.mdb)|*.mdb';
openDL.InitialDir := ExtractFileDir(Application.ExeName);
end;procedure TBackupDBForm.btnLoginClick(Sender: TObject);
begin
inherited;
LoadConstBR;
end;procedure TBackupDBForm.ButDataPathClick(Sender: TObject);
begin
inherited;
if edtoldData.Text <> '' then
begin
// if BRConst = BACKUP then
// begin
// if Not DirectoryExists('数据库备份路径!', '', Dir) then Exit;
// GetDir(Dir, BACKUP);
// end
// else
// if BRConst = RESTORE then
// begin
// if Not DirectoryExists('数据库还原路径!', '', Dir) then Exit;
// edtNewData.Text := dir;
// GetDir(Dir, RESTORE);
// end;
end
else
begin
if BRConst = BACKUP then
begin
ShowMsg('请选择需要备份的数据库!');
edtoldData.SetFocus;
end
else
if BRConst = RESTORE then
begin
ShowMsg('请选择需要还原的数据库!\');
edtoldData.SetFocus;
end;
end;
end;procedure TBackupDBForm.cxButton1Click(Sender: TObject);
begin
inherited;
if Not openDL.Execute then Exit;
edtoldData.Text := openDL.FileName;
end;procedure TBackupDBForm.GetDir(path: string; BorR: integer);
begin
shortdateformat := 'yymmdd'; //格式化日期 2004.5.10 -> 040510
if BRConst = BACKUP then
begin
if (StrLen(PChar(Path)) <> 3) then
edtNewData.Text := path + '\' +GetmdfName(edtOldData.Text) +
DatetoStr(date) + '.mdb'
else
edtNewData.Text := path + GetmdfName(edtOldData.Text) + DatetoStr(date) +
'.mdb';
end
else
if BRConst = RESTORE then
begin
if (StrLen(PChar(Path)) <> 3) then
edtNewData.Text := path + '\BgStudent.mdb'
else
edtNewData.Text := path + 'BgStudent.mdb';
end
end;function TBackupDBForm.GetmdfName(Path: string): string;
var
s1: string;
begin
s1 := Path;
while Pos('\', s1) <> 0 do // c:\aa\bb\cc.mdb
s1 := copy(s1, pos('\', s1) + 1,length(s1));
result := copy(s1, 0, Pos('.', s1) - 1);
end;procedure TBackupDBForm.LoadConstBR;
begin
if edtNewData.Text = '' then
begin
if BRConst = BACKUP then
begin
ShowMsg('请选择需要备份数据库的路径!');
edtNewData.SetFocus ;
exit;
end
else
if BRConst= RESTORE then
begin
ShowMsg('请选择需要还原数据库的路径!');
edtNewData.SetFocus;
exit;
end;
end; try
if FileExists(Trim(edtNewData.Text)) then
begin
if application.MessageBox('你是否要覆盖吗?', '系统提示',
mb_yesno + mb_iconquestion) = ID_NO then
exit
else
begin
CopyFile(PChar(edtOldData.Text),PChar(edtNewData.Text),false);
if BRConst = BACKUP then
ShowMsg('数据库备份成功!' )
else
if BRConst = RESTORE then
ModalResult := mrOk;
end ;
end
else
begin
CopyFile(PChar(edtOldData.Text),PChar(edtNewData.Text),false);
if BRConst=BACKUP then
ShowMsg('数据库备份成功!' )
else
if BRConst=RESTORE then
ModalResult := mrOk;
end;
except if BRConst = BACKUP then
begin
ShowMsg('请选择需要备份的数据库! ');
edtoldData.SetFocus;
end
else
if BRConst= RESTORE then
begin
ShowMsg('请选择需要还原的数据库! ');
edtNewData.SetFocus;
end;
end;
end; procedure TBackupDBForm.MainShow;
begin
if BRConst=BACKUP then
begin
self.Caption:='备份数据库';
ButDataPath.Caption:='备份路径';
openDL.Title:='选择需要备份的数据库';
end
else
if BRConst=RESTORE then
begin
self.Caption:='还原数据库';
ButDataPath.Caption:='还原路径';
openDL.Title:='选择需要还原的数据库';
end;
end;initialization RegisterClass(TBackupDBForm);finalization UnRegisterClass(TBackupDBForm);end.---------------------------------------------------------------------------