下面这个程序,是把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.
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.
解决方案 »
- 请教高手动态的切换SDI和MDI窗体时报错怎么解决?
- 急!!!请问如何控制属于网络打印机Epson 300K 进行 进纸、退纸操作...
- 高分求救,中断一个正在执行的查询时遇到"operation cannot be performed while executing asynchronously"错误
- 100分,大家集思广言,不够再加分
- 水晶报表、的问题,向高手请教,想学习水晶报表的也一起进来吧!在线等待
- 菜鸟提问:TOOLBUTTON控件的用法。
- 有没有可以得到cpu序列号的函数
- 如何打开关闭dvd光驱?
- 数据库还原问题
- 重述一下本人的问题?
- 如何查询取出分类的最下层
- delphi中的dbchart能够实现下面这个图的功能吗
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;