我正在处理此代码,但它给了我一个错误,提示错误类型:ADODB.Recordset (0x800A0E79) 对象打开时不允许操作。我以前从未遇到过这个错误。我要做的是在特定文件夹中掺杂新文件时更新访问文件。我用完美工作的excel做同样的事情,当我向它添加访问部分时,它给了我错误。这是我的代码,如果我能得到一些帮助,那就太好了。
<!--#include file="header.inc"-->
<%
file = Request.querystring("file")
file = "C:\Reports\" & file
log("UPDATE UTILITY RUN---------" & file)
'Initialize Connection to report
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set rows = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & file & ";" & _
"Extended Properties=" & Chr(34) & "Excel 12.0 Xml;HDR=No;IMEX=1" & Chr(34) & ";"
'Initlialize Connection to Data
Set objConnection2 = CreateObject("ADODB.Connection")
Set rows2 = CreateObject("ADODB.Recordset")
objConnection2.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & Server.MapPath("data.xlsx") & ";" & _
"Extended Properties=" & Chr(34) & "Excel 12.0 Xml;HDR=Yes;IMEX=0" & Chr(34) & ";"
'initialize Connection3 to Data
Set objConnection3 = CreateObject("ADODB.Connection")
Set rows3 = CreateObject("ADODB.Recordset")
objConnection3.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &
Server.MapPath("tracker_dev_nik.accdb") & ";Persist Security Info=False;"
'Query the spreadsheet
rows.Open "Select * FROM [WC-Stages$]", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
'Print off the row's data
DIM JUR
DIM WC
DIM WC_NAME
DIM PRIORITY
DIM REP
DIM DELIVER
DIM ACCEPT
DIM REJECT
DIM REDELIVER
DIM STATUS
DIM SDATE
DIM DATA_STATUS
DIM DATA_STATUS_2
DIM DATA_SDATE
DIM DATA_SDATE_2
Do Until rows.EOF
JUR = rows.Fields("F3").Value
WC = rows.Fields("F4").Value
WC_NAME = rows.Fields("F5").Value
PRIORITY = rows.Fields("F7").Value
REP = rows.Fields("F23").Value
DELIVER = rows.Fields("F22").Value
ACCEPT = rows.Fields("F24").Value
REJECT = rows.Fields("F25").Value
REDELIVER = rows.Fields("F26").Value
STATUS = ""
SDATE = ""
DATA_STATUS = ""
DATA_SDATE = ""
IF NOT ( JUR = "" OR JUR = "Jur" ) THEN 'Ignore invalid rows (first two and
last three)
If IsNull(DELIVER) THEN
STATUS = "undelivered"
SDATE = "1/1/2000"
ELSE
IF IsNull(ACCEPT) THEN
IF IsNull(REJECT) THEN
STATUS = "delivered"
SDATE = DELIVER
ELSE
IF IsNull(REDELIVER) THEN
STATUS = "rejected"
SDATE = REJECT
ELSE
STATUS = "redelivered"
SDATE = REDELIVER
END IF
END IF
ELSE
STATUS = "accepted"
SDATE = ACCEPT
END IF
END IF
query = "SELECT * FROM [Sheet1$] WHERE JUR = '" & JUR & "' AND WC = " & WC
rows2.Open query, _
objConnection2, adOpenStatic, adLockOptimistic, adCmdText
'For access database connection
query = "SELECT * FROM [Sheet1] WHERE JUR = '" & JUR & "' AND WC = " & WC
rows3.Open query, _
objConnection3, adOpenStatic, adLockOptimistic, adCmdText
' DATA_STATUS = rows2.Fields("Status").Value
' DATA_SDATE = rows2.Fields("SDate").Value
DATA_STATUS = rows3.Fields("Status").Value
DATA_SDATE= rows3.Fields("SDate").Value
if dateafter( SDATE, DATA_SDATE ) AND STATUS <> DATA_STATUS then
'Need to update the data with the new value
log("UPDATE: " & jur & ":" & wc & "has been changed to " & STATUS)
query = "UPDATE [Sheet1] SET [STATUS] = '" & STATUS & "', [SDATE] =
'" & SDATE & "' WHERE [JUR] = '" & JUR & "' AND [WC] = " & WC
response.write(query)
objConnection3.execute(query)
END IF
rows2.close
END IF
rows.MoveNext
Loop
log("UPDATE COMPLETE")
%>
<!--#include file="footer.inc"-->
谢谢尼克