下面这个程序,是把EXCEL表中的数据导入access数据库,但是我运行之后只把第一行数据导入了,其他行全是空白!!请高手帮帮忙!!!代码如下
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOQuery1.Open;
try
  ADOConnection1.Connected:=true;
 Except
  Application.MessageBox('数据库连接失败,请检查参数!','警告',mb_iconwarning)
 end;
end;procedure TForm1.RzBitBtn1Click(Sender: TObject);
var
 i:integer;
 excela:string;
 excelb:string;
 excelc:string;
 exceld:string;
 ExcelApp,workbook,ExcelRowCount:oleVariant;
begin
    if  RzOpenDialog1.Execute then
    begin
      try
        ExcelApp:=CreateOleObject('Excel.Application');
        WorkBook := ExcelApp.WorkBooks.Open(RzOpenDialog1.FileName);//使用opendialog对话框指定
        ExcelApp.Visible := false;
        ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
        ADOQuery1.Open;
        for i := 1 to excelrowcount + 1 do
          begin
            excela:=ExcelApp.cells[i,1].value;
            excelb:=ExcelApp.cells[i,2].value;
            excelc:=ExcelApp.cells[i,3].value;
            exceld:=ExcelApp.cells[i,4].value;
            ADOQuery1.Append;
            ADOQuery1.FieldByName('FullName').asstring:=excela;
            ADOQuery1.FieldByName('Date').asstring := excelb;
            ADOQuery1.FieldByName('ComeTime').asstring := excelc;
            ADOQuery1.FieldByName('GoTime').AsString:= exceld;
            ADOQuery1.post;
            //ADOQuery1.ApplyUpdates(-1);
            ADOQuery1.UpdateBatch;
            end;
            showmessage('导入数据成功!')
       finally
         WorkBook.Close;
         ExcelApp.Quit;
         ExcelApp := Unassigned;
         WorkBook := Unassigned;
       end;
    end;
end;
end.

解决方案 »

  1.   

    我增加了2个按钮,代码如下:
    procedure TForm1.RzBitBtn3Click(Sender: TObject); (删除按钮)
    begin
    if Application.MessageBox('确认删除数据吗?','询问',mb_yesno)=idyes then
      begin
       ADOQuery1.Delete;
       ADOQuery1.UpdateBatch(-1);  end;
       [Error] Unit1.pas(101): Incompatible types: 'TAffectRecords' and 'Integer'
    end;
    procedure TForm1.RzBitBtn5Click(Sender: TObject);
    begin
    ADOQuery1.UpdateBatch(-1);
    [Error] Unit1.pas(101): Incompatible types: 'TAffectRecords' and 'Integer'

    end;