转换的源码
procedure TfrmConvertDB.btnOKClick
(Sender:TObject);
variField:integer;
begin
if ((edTotbl.text<>'') and (edFromtbl.text<>'')) then
begin
tblSource.TableName:=edFromtbl.text; {指定TableName}
tblDest.TableName:=edTotbl.text;
with tblSource do
begin
Open;{打开老系统的表}
While EOF=FALSE do
begin{逐条记录处理}
qryInsert.SQL.Clear;
qryInsert.sql.Add('Insert into'+edTotbl.text+' ( ' );
for iField:=0 to dbg.FieldCount-1 do
begin
qryInsert.sql.add(dbg.Fields[iField].DisplayLabel);
if iField<>dbg.FieldCount-1then
qryInsert.sql.add('');
end;
qryInsert.sql.add(' )values(' );
for iField:=0 to dbg.FieldCount-1 do
begin
{进行数据类型转换}
if dbg.fields[iField].DataType=ftInteger then
qryInsert.sql.add(inttostr(dbg.fields[iField].asInteger));
if dbg.fields[iField].DataType=ftFloat then
qryInsert.sql.add(floattostr(dbg.fields[iField].asFloat));
if dbg.fields[iField].DataType=ftDate then
qryInsert.sql.add(''''+datetostr(dbg.fields[iField].asDateTime)+'''');
if dbg.fields[iField].DataType=ftString then
begin
if dbg.fields[iField].asString<>'' then
qryInsert.sql.add(''''+dbg.fields[iField].asString+'''')
else
qryInsert.sql.add('NULL');
end;
if iField<>dbg.FieldCount-1 then qryInsert.sql.add(' ');
end;
qryInsert.sql.add(')');
qryInsert.ExecSQL; {把数据插入到新系统的表中}
next;
end;
end;
tblDest.Close;
tblDest.Open;;
ShowMessage('转换完毕!');
end
else
ShowMessage('请输入要插入数据的表的名称');
end;
end.
建立的access数据库的数值字段可以为空,没有强制非空