0

我有以下代码将 Excel 数据导入表并更新一些参数,但是我无法读取所有行,只读取最后一行,我希望能够读取所有行并更新它们的值桌子

DECLARE c CURSOR FOR select  Barcode,MSISDN,POS,[SIM Card Number],[Date of Sale] FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel     12.0;Database=C:\ActivatedCards.xlsx;HDR=YES', 'SELECT Barcode,MSISDN,POS,[SIM Card     Number],[Date of Sale] FROM [sheet1$]')
declare @Barcode as bigint
declare @MSISDN as bigint
declare @POS as nvarchar(50)
declare @SIMCardNb as bigint
declare @ActivatedDate as date

begin

open c 

fetch next from c into @Barcode,@MSISDN,@POS,@SIMCardNb,@ActivatedDate


WHILE @@FETCH_STATUS = 0
begin
select @Barcode=Barcode,@MSISDN=MSISDN,@POS=POS,@SIMCardNb=[SIM Card     Number],@ActivatedDate=[Date of Sale] FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel  12.0;Database=C:\ActivatedCards.xlsx;HDR=YES', 'SELECT Barcode,MSISDN,POS,[SIM Card  Number],[Date of Sale] FROM [sheet1$]')
where Barcode <> ''

Update Cards 
set 
MSISDN=@MSISDN ,
POSSold=@POS,
Activated=1,
SIMCardNb=@SIMCardNb,
ActivatedDate=@ActivatedDate,
ImportDate=GETDATE(),
CollectionDeadlineDate=DateAdd(Day,30,ImportDate)
where Cards.BarCode=@Barcode


fetch next from c into @Barcode,@MSISDN,@POS,@SIMCardNb,@ActivatedDate
end 


CLOSE c
DEALLOCATE c
4

1 回答 1

0

使用 NPOI api 读取/写入 xls、doc、ppt 文件。microsoft Microsoft.ACE.OLEDB.12.0' 内置 api 不适合此任务。

易于使用且非常高效的示例可以在下面找到。

http://npoi.codeplex.com/

于 2013-05-20T10:07:19.090 回答