I have a ASP page where a user will upload a excel file. After the file is successfully uploaded I want to take the rows in the REGION tab and insert them into an MS Access 2007 table. Below is the code I used and I am getting this error. Can I use the recordset update with the Microsoft.ACE.OLEB.12.0 provider? Is there a better way to do this?
ADODB.Recordset error ‘800a0cb3’
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
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
Thank you Hans, Tim and Remou. I followed this example Using INSERT INTO to write data into access database