首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么从一个表向另一个表"成批拷贝记录"用的是ACCESS

2012-03-13 
如何从一个表向另一个表成批拷贝记录,用的是ACCESS!如何从一个表向另一个表 成批拷贝记录 ,用的是ACCE

如何从一个表向另一个表"成批拷贝记录",用的是ACCESS!
如何从一个表向另一个表 "成批拷贝记录 ",用的是ACCESS!
而不用循环语句,是否可以弄个存储过程?

我现在用的是这样的:


Sum:=0;
                      with   ADOTable1   do
                      begin
                                First;
                                while   not   eof   do
                                begin
                                    Sum:=Sum+{ADOTable1.FieldByName( 'GoodsSum ').AsFloat+}   FieldByName( 'UnitPrice ').AsFloat*FieldByName( 'Quantity ').AsInteger;
                                    //将明细表的金额累加到主表的金额字段
                                      Str:= 'Insert   into   BillsDetail   (BillNo,CreateDate, '+
                                                'EmployeeID,ClientID,GoodsID,GoodsName,GoodsUnit,Quantity,UnitPrice,GoodsSum,delFlag)   Values( ';
                                                Str:=Str+ ' " '+   ls_tkdh+ ' ", '   ;       //单号
                                                Str:=Str+ ' " '+   datee+ ' ", '   ;           //日期
                                                Str:=Str+ ' " '+   '01 '+ ' ", '   ;           //操作员
                                                Str:=Str+ ' " '+   'Client '+ ' ", '   ;             //所属客户编号
                                                Str:=Str+ ' " '+   ADOTable1.FieldByName( 'GoodsID ').AsString+ ' ", '   ;             //货物编号
                                                Str:=Str+ ' " '+   VartoStr(ADOTable1.FieldByName( 'GoodsName1 ').AsString)+ ' ", '   ;             //商品名
                                                Str:=Str+ ' " '+   VartoStr(ADOTable1.FieldByName( 'GoodsUnit ').AsString)+ ' ", '   ;             //单位


                                                Str:=Str+   VartoStr(ADOTable1.FieldByName( 'Quantity ').AsInteger)+ ', '   ;             //数量
                                                Str:=Str+   VarToStr(ADOTable1.FieldByName( 'UnitPrice ').AsFloat)+ ', '   ;             //单价
                                                Str:=Str+   VarToStr(FieldByName( 'GoodsSum ').AsFloat)+ ', ';     //本行的金额
                                                Str:=Str+ ' " '+   ADOTable1.FieldByName( 'delFlag ').AsString+ ' ") '   ;             //标志
                                                ShowMessage(str);
                                                try
                                                    with   ADOCommand1   do
                                                    begin
                                                          Connection   :=ADOConnection1;
                                                          CommandText   :=   Str;
                                                          CommandType   :=   cmdText;
                                                          //ADODataSet1.Recordset   :=
                                                          Execute;
                                                    end;
                                                    //ls_tkdh:=ADODataSet1.Recordset.Fields[0].Value;       //取RecordSet中记录的方法


                                                except
                                                    on   E:   Exception   do
                                                      begin
                                                          ShowMessage(E.Message);
                                                      end;
                                                end;

                                                Next;
                                end;
                        end;

[解决办法]
不同的數據庫用. TBatchMove
同一個Access用SQL就好了.
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
var
ssql1,insertsql:string;
begin
ssql1 := 'Select * from ssinf ';
with Adoquery1 do
begin
Close;
SQL.Text := ssql1;
Open;
first;
while not Eof do
begin
ADOQuery2.Append;
ADOQuery2.FieldByName( 'Name ').AsString := FieldByName( 'Name ').AsString;
ADOQuery2.Post;
end;
end;
end;
[解决办法]
INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression

看看ACCESS中的幫助信息
[解决办法]
一句就够了阿 insert into table1(zd1,zd2....)(select zd1,zd2.... from table2 where XX=XX)

热点排行