当导入这个EXCEL文档到SQL时报错could not variant of type (string)  into type (double)
请大虾看一下DELPHI语句存在什么问题?要怎么更改?? 
1、EXCEL文-------------------------------------
1 E103-0000JB-B30 电子 30
2 E103-0000JF-C30 电子 4
3 E103-0100JB-B30 电子 22SQL数据结构----------------------------------------
fid,fnumber,fname,fqty
char char   char  char
注FID、FQTY为INT也可以 但是也是报错DELPHI语句-----------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
excelx,excelf : string;
excely,excelz: string;
ExcelApp,workbook,ExcelRowCount: Variant;
i:integer;
begin
opendialog1.filter:='Excel文档(*.xls)|*.xls';
opendialog1.InitialDir:='c:\';
opendialog1.Execute;
Try
ExcelApplication1.Connect;//EXCEL应用程序
Except
MessageDlg('Excel may not be installed',mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
try
ExcelApp := CreateOleObject('Excel.Application');
WorkBook := ExcelApp.WorkBooks.Open(opendialog1.FileName);//使用opendialog对话框指定
//excel档路径
ExcelApp.Visible := false;
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
for i := 1 to excelrowcount + 1 do
begin
excelx := excelapp.Cells[i,1].Value;
excely := excelapp.Cells[i,2].Value;
excelz := excelapp.Cells[i,3].Value;
excelf := excelapp.Cells[i,4].Value;
if ((excelapp.Cells[i,1].Value = '') and (ExcelApp.Cells[i,2].Value = '') and (ExcelApp.Cells[i,3].Value = '') and (ExcelApp.Cells[i,4].Value = '') )   then
exit
elsewith adoquery1 do
begin
close;
sql.clear;
sql.add('insert into topr(fid,fnumber,fname,fqty) values(:fid,:fnumber,:fname,:fqty)');
Parameters.ParamByName('fid').Value  :=excelx;
Parameters.ParamByName('fnumber').Value  := excely;
Parameters.ParamByName('fname').Value  := excelz;
Parameters.ParamByName('fqty').Value  := excelf;
execsql;
end;end; finally WorkBook.Close; ExcelApp.Quit; ExcelApp := Unassigned; WorkBook := Unassigned;end; end;

解决方案 »

  1.   


    1、EXCEL文------------------------------------- 
    1 E103-0000JB-B30 电子 30 
    2 E103-0000JF-C30 电子 4 
    3 E103-0100JB-B30 电子 22
    所有都是文档的话就还不会报错可以正常导入
    如1、EXCEL文------------------------------------- 
    rr E103-0000JB-B30 电子 r 
    r E103-0000JF-C30 电子 r 
    r E103-0100JB-B30 电子 r
    这种格式就可以
      

  2.   

    excel导入sql的问题,研究了好长时间,除了在企业管理器上操作之外,其他的方法还没弄成功过。