K
keven_zk
Unregistered / Unconfirmed
GUEST, unregistred user!
大哥,我的积分快完了,但是我的问题还没有解决,
你可不可以救救命,!可不可以解释一下foxpro 和sql server 的数据类型
转换一块的意思????
unit ConvertDBF;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, DBTables, Db, Grids, DBGrids;
type
TfrmConvertDB = class(TForm)
btnOK: TButton;
Label1: TLabel;
db1: TDatabase; {用于连接老数据库系统}
db2: TDatabase; {用于连接新数据库系统}
dbg: TDBGrid;
tblSource: TTable; {dbg的Datasource}
qryInsert: TQuery;
{用于存放生成的SQL Insert语句}
srcSource: TDataSource;
tblDest: TTable; {DBGrid1的Datasource}
DBGrid1: TDBGrid;
srcDest: TDataSource;
edFromtbl: TEdit;
Label2: TLabel;
Label3: TLabel;
edToTbl: TEdit;
procedure btnOKClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmConvertDB: TfrmConvertDB;
implementation
{$R *.DFM}
procedure TfrmConvertDB.btnOKClick
(Sender: TObject);
var iField :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-1 then
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.
你可不可以救救命,!可不可以解释一下foxpro 和sql server 的数据类型
转换一块的意思????
unit ConvertDBF;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, DBTables, Db, Grids, DBGrids;
type
TfrmConvertDB = class(TForm)
btnOK: TButton;
Label1: TLabel;
db1: TDatabase; {用于连接老数据库系统}
db2: TDatabase; {用于连接新数据库系统}
dbg: TDBGrid;
tblSource: TTable; {dbg的Datasource}
qryInsert: TQuery;
{用于存放生成的SQL Insert语句}
srcSource: TDataSource;
tblDest: TTable; {DBGrid1的Datasource}
DBGrid1: TDBGrid;
srcDest: TDataSource;
edFromtbl: TEdit;
Label2: TLabel;
Label3: TLabel;
edToTbl: TEdit;
procedure btnOKClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmConvertDB: TfrmConvertDB;
implementation
{$R *.DFM}
procedure TfrmConvertDB.btnOKClick
(Sender: TObject);
var iField :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-1 then
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.