在Delphi写SQL语句,从一个表向另一个表复制数据,出错。怎么办?
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
ADOTable2: TADOTable;
ADOTable3: TADOTable;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
DBGrid3: TDBGrid;
DataSource1: TDataSource;
DataSource2: TDataSource;
DataSource3: TDataSource;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
connectstr:string;
begin
connectstr:=GetCurrentDir+'\SCCS.MDB;';
ADOTable1.ConnectionString:=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+connectstr+'Persist Security Info=False';
ADOTable2.ConnectionString:=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+connectstr+'Persist Security Info=False';
//connectstr:=GetCurrentDir+'\DCB.MDB;';
connectstr:=GetCurrentDir+'\DCB1.MDB;';
ADOTable3.ConnectionString:=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+connectstr+'Persist Security Info=False';
ADOQuery1.ConnectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+connectstr+'Persist Security Info=False';
ADOTable1.TableName:='sk';
ADOTable2.TableName:='cy';
ADOTable3.TableName:='DC';
ADOTable1.Active:=true;
ADOTable2.Active:=true;
ADOTable3.Active:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var
querystr:string;
begin
{将sk数据导入到DC表中}
ADOTable1.Active:=false;
ADOTable2.Active:=false;
ADOTable3.Active:=false;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
querystr:='Delete from DC';
ADOQuery1.SQL.Add(querystr);
ADOQuery1.ExecSQL;
//ADOTable1.Active:=true;
//ADOTable2.Active:=false;
//ADOTable3.Active:=false;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
//querystr:='insert into dc (测点顺序号,射孔井段顶深,射孔井段底深,层位,生产层位)';
//querystr:='insert into dc(CDSXH,SKJD1,SKJD2,CW,SCCW)';
//querystr:=querystr+'select * from sk';
querystr:='insert into dc(CDSXH,SKJD1,SKJD2,CW,SCCW) select * from sk';
ADOQuery1.SQL.Add(querystr);
ADOQuery1.ExecSQL;
showmessage('导入完毕。');
end;
end.