我以前发给客户的数据库是旧的,有些字段和表都没有,现在升级应用程序后,老的数据库就必须升级才能用,现在想写一个升级数据库的程序给客户,能实现遍历整个旧的数据库然后和新数据库比较,旧的数据库没有的表或者字段自动创建。我用的是ACCESS数据库。
解决方案 »
- 截取后边3位数
- 关于图形放大的问题
- Delphi2006操作MySQL出错,是我的问题还是Delphi2006本身的问题?
- 找不到Sqlserver,怎么设置?
- 用adodataset连接数据库,如何删除选中的记录?
- 多个MP3文件可以用程序合成一个吗?怎么编程或使用什么控件?谢谢!
- 一个数据表的刷新问题?
- 一个字窗体关闭的问题,高手请进
- 各位仁兄帮小妹一把,帮我看看这条sql cursor 语句对不对?到十一前就的上交了......不好意思,刚进来,没有太多分给各位。拜托拜托!
- 求教!关于写数据库的问题。
- 怎样把程序缩成托盘图标
- ◆◆◆◆◆◆DELHI8 无法正常编译程序~请高人指教◆◆◆◆◆◆
ADOConnection1.GetTableNames(...);
ADOConnection1.GetFieldNames(...);
获得表名称以及指定表的字段值,然后再根据需要用SQL语句修改就好了
procedure TForm1.Button1Click(Sender: TObject);
var
TableList: TStringList;
FieldList: TStringList;
I: Integer;
begin
TableList := TStringList.Create;
FieldList := TStringList.Create;
ADOConnection1.GetTableNames(TableList);
for I := 0 to TableList.Count - 1 do
begin
ADOConnection1.GetFieldNames(TableList[I], FieldList);
//此时FieldList中已经包含了 TableList[I]的全部字段
end;
FieldList.Free;
TableList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TableListOld, TableListNew: TStringList;
FieldListOld, FieldListNew: TStringList;
I, J: Integer;
begin
TableListOld := TStringList.Create;
FieldListOld := TStringList.Create;
TableListNew := TStringList.Create;
FieldListNew := TStringList.Create;
ADOConnectionOld.GetTableNames(TableListOld);
ADOConnectionNew.GetTableNames(TableListNew);
for I := 0 to TableListNew.Count - 1 do
begin
ADOConnectionNew.GetFieldNames(TableListNew[I], FieldListNew);
if TableListOld.IndexOf(TableListNew[I]) <> -1 then
begin
//旧数据库中表TableListNew[I]存在
ADOConnectionOld.GetFieldNames(TableListNew[I], FieldListOld);
for J := 0 to FieldListNew.Count - 1 do
begin
if FieldListOld.IndexOf(FieldListNew[J]) <> -1 then
begin
{ 旧数据库表TableListNew[I]中 字段FieldListNew[J]存在 }
end else
begin
{ 旧数据库表TableListNew[I]中 字段FieldListNew[J]不存在,修改表TableListNew[I]的字段 }
end;
end;
end else
begin
{ 旧数据库中表TableListNew[I]不存在,创建表TableListNew[I] }
end;
end;
TableListOld.Free;
TableListNew.Free;
FieldListOld.Free;
FieldListNew.Free;
end;