我有一个 ASP 页面,用户将在其中上传一个 excel 文件。文件成功上传后,我想获取 REGION 选项卡中的行并将它们插入到 MS Access 2007 表中。下面是我使用的代码,我收到了这个错误。我可以将记录集更新与 Microsoft.ACE.OLEB.12.0 提供程序一起使用吗?有一个更好的方法吗?ADODB.Recordset 错误“800a0cb3”
当前记录集不支持更新。这可能是提供者或所选锁类型的限制。
Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strExcelFile & ";" & _
"Extended Properties=" & Chr(34) & "Excel 12.0 Xml;HDR=Yes;IMEX=1" & Chr(34) & ";"
Response.Write "Excel connection opened<BR>"
' Load ADO Recordset with Excel Data
Set rstExcel = Server.CreateObject("ADODB.Recordset")
rstExcel.Open "Select * from [REGION$]", cnnExcel, adOpenStatic
Response.Write "Excel Recordset loaded<BR>"
' Open Access Connection
Set cnnAccess = Server.CreateObject("ADODB.Connection")
cnnAccess.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strAccessFile & ";Persist Security Info=False;"
Response.Write "Access connection opened<BR>"
Const adOpenStatic = 1
Const adLockOptimistic = 3
Const adCmdText = &H0001
' Load ADO Recordset with Access Data
Set rstAccess = Server.CreateObject("ADODB.Recordset")
rstAccess.Open "REGION", cnnAccess, adOpenStatic, adLockOptimistic, adCmdTable
Response.Write "Access Recordset loaded<BR>"
' Synchronize Recordsets and Batch Update
Do Until rstExcel.EOF
' .AddNew
For each field in rstExcel.Fields
If field.Name = "% Over/Under" Then
rstAccess.AddNew field.Name,0
Else
rstAccess.AddNew field.Name,field.Value
End If
Next
rstExcel.MoveNext
Loop
rstAccess.UpdateBatch