一下是批量导入函数源代码,请帮忙查下原因,谢谢! function TStockIn.InitExcelOrder:Integer; var ExcelApp:Variant; var i,j,m,num_pro:Integer; var s_e1,s_e2,s_e3,s_e4,s_e5,s_e6,s_e7,s_e8,s_e9,s_e10:string; begin i:=3;j:=0;num_pro:=0; ExcelApp:=CreateOleObject('Excel.Application'); ExcelApp.Caption:='应用程序调用 Microsoft Excel'; ExcelApp.workBooks.Open(RzOpenDialog1.FileName); try ExcelApp.Worksheets['入库导入模板'].activate; except PC.M(DATA_ACTION_ERROR); Result := 1; Exit; end; while not(ExcelApp.Cells[i,9].Value='') do begin i:=i+1; num_pro:=num_pro+1; end; while j<num_pro do begin m:=j+3; s_e1:=IntToStr(PC.transProductSpecToProductID(ExcelApp.Cells[m,1].Value));//物料号 s_e2:=IntToStr(PC.transGroupNameToGroupID(ExcelApp.Cells[m,2].Value)); //库位 s_e3:=ExcelApp.Cells[m,3].Value; //入库单号 s_e5:=ExcelApp.Cells[m,4].Value; //数量 s_e4:=ExcelApp.Cells[m,5].Value; //批号 s_e6:=ExcelApp.Cells[m,6].Value; //入库日期 s_e7:=ExcelApp.Cells[m,7].Value; //生产日期 s_e9:=ExcelApp.Cells[m,8].Value; //备注 s_e10:=IntToStr(PC.transStatusNameToStatusID(ExcelApp.Cells[m,9].Value)); s_e8:=IntToStr(PC.transStatusNameToStatusID(ExcelApp.Cells[m,10].Value)); With ADOQuery2 do begin SQL.Clear; SQL.Text:='exec [dbo].[sp_quick_purchase] '+QuotedStr(s_e1)+','+'5'+','+QuotedStr(s_e2)+','+QuotedStr(s_e3)+','+QuotedStr(s_e4)+','+(s_e5)+','+QuotedStr(s_e6); SQL.Text:=SQL.Text+','+QuotedStr(s_e7)+','+QuotedStr(s_e8)+','+QuotedStr(s_e9)+','+QuotedStr(s_e10); Log.WriteLog(2,Log.UserLogon(12,SYSTEM_OPERATOR,PC.NormalizeSQL(SQL.Text))); //日志SQL //PC.M(SQL.Text); ExecSQL; //PC.DirectMSG(DATA_RETURN_MSG,DATA_ADD_SUCCESSFUL); Log.WriteLog(2,Log.UserLogon(2,SYSTEM_OPERATOR,QUICK_PURCHASE)); end; inc(j); end; PC.DirectMSG(DATA_RETURN_MSG,DATA_QUICK_ADD_SUCCESSFUL); ExcelApp.ActiveWorkBook.Saved := True; ExcelApp.WorkBooks.Close; ExcelApp.Quit; ExcelApp:=Unassigned; RefreshGrid(0); Result := 0; end;
你这个问题还是用IDE调试一下吧,说的这么笼统真不好帮你解答,初步断定可能是SQL语句非法的问题
function TStockIn.InitExcelOrder:Integer;
var ExcelApp:Variant;
var i,j,m,num_pro:Integer;
var s_e1,s_e2,s_e3,s_e4,s_e5,s_e6,s_e7,s_e8,s_e9,s_e10:string;
begin
i:=3;j:=0;num_pro:=0;
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.Caption:='应用程序调用 Microsoft Excel';
ExcelApp.workBooks.Open(RzOpenDialog1.FileName);
try
ExcelApp.Worksheets['入库导入模板'].activate;
except
PC.M(DATA_ACTION_ERROR); Result := 1;
Exit;
end;
while not(ExcelApp.Cells[i,9].Value='') do
begin
i:=i+1;
num_pro:=num_pro+1;
end;
while j<num_pro do
begin
m:=j+3;
s_e1:=IntToStr(PC.transProductSpecToProductID(ExcelApp.Cells[m,1].Value));//物料号
s_e2:=IntToStr(PC.transGroupNameToGroupID(ExcelApp.Cells[m,2].Value)); //库位
s_e3:=ExcelApp.Cells[m,3].Value; //入库单号
s_e5:=ExcelApp.Cells[m,4].Value; //数量
s_e4:=ExcelApp.Cells[m,5].Value; //批号
s_e6:=ExcelApp.Cells[m,6].Value; //入库日期
s_e7:=ExcelApp.Cells[m,7].Value; //生产日期
s_e9:=ExcelApp.Cells[m,8].Value; //备注
s_e10:=IntToStr(PC.transStatusNameToStatusID(ExcelApp.Cells[m,9].Value));
s_e8:=IntToStr(PC.transStatusNameToStatusID(ExcelApp.Cells[m,10].Value));
With ADOQuery2 do
begin
SQL.Clear;
SQL.Text:='exec [dbo].[sp_quick_purchase] '+QuotedStr(s_e1)+','+'5'+','+QuotedStr(s_e2)+','+QuotedStr(s_e3)+','+QuotedStr(s_e4)+','+(s_e5)+','+QuotedStr(s_e6);
SQL.Text:=SQL.Text+','+QuotedStr(s_e7)+','+QuotedStr(s_e8)+','+QuotedStr(s_e9)+','+QuotedStr(s_e10);
Log.WriteLog(2,Log.UserLogon(12,SYSTEM_OPERATOR,PC.NormalizeSQL(SQL.Text))); //日志SQL
//PC.M(SQL.Text);
ExecSQL;
//PC.DirectMSG(DATA_RETURN_MSG,DATA_ADD_SUCCESSFUL);
Log.WriteLog(2,Log.UserLogon(2,SYSTEM_OPERATOR,QUICK_PURCHASE));
end;
inc(j);
end;
PC.DirectMSG(DATA_RETURN_MSG,DATA_QUICK_ADD_SUCCESSFUL);
ExcelApp.ActiveWorkBook.Saved := True;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp:=Unassigned;
RefreshGrid(0);
Result := 0;
end;