我最近继承了一个用VBScript编写的DTS包,我没有接触过很多VBS,并想检查我添加了'的功能。我是否需要一个rs1.close这里的评论应该在关闭rs1对象之后重新设置它?。
Function Proc_Amend()
On error resume next
dtspackagelog.writestringtolog "Start Proc_Amend at " & Time
' Check record to be amended exists
set rs1 = cn1.execute("SELECT StatusFlag from wmLoadId where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If rs1.eof then
Err.Raise 9994 , , "Record to be amended DOES NOT exist"
Call ErrHand(err.number,err.description)
Else
If UCASE(rs1.fields("StatusFlag").value) = "PENDING" Then
iarray(14) = "PENDING"
End If
' Do i need a rs1.close here
set rs1 = cn1.execute("UPDATE wmLoadId set OrderWeight = " & iarray(9) & ",StatusFlag='" & iarray(14) & "',Timestamp = getdate() where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If Err Then
' An error occurred so process
Call ErrHand(err.number,err.description)
End If
' Check and update planned_ship_date (if reqd.)
' Do i need a rs1.close here
set rs1 = cn1.execute("SELECT planned_ship_date from Add_Info where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If rs1.eof then
Err.Raise 9988 , , "No Add_Info record exists to update"
Call ErrHand(err.number,err.description)
Else
cm.CommandText="select convert(varchar(10),wanted_delivery_date,103) AS PlanShip from OPENQUERY(DB33,'select wanted_delivery_date from CUSTOMER_ORDER_LINE_TAB where order_no=''" & iarray(2) & _
"'' and LINE_NO = ''" & iarray(4) & "'' AND REL_NO = ''" & iarray(5) & "'' ' ) "
dtspackagelog.writestringtolog "Planned_Ship_Date (amend) command is " & cm.CommandText
set rs = cm.execute()
dtspackagelog.writestringtolog "Err status after Planned_Ship_Date (amend) command is " & err.number & " at " & Time
if rs.eof then
On Error Resume Next
dtspackagelog.writestringtolog "No CUSTOMER_ORDER record found for order line (amend) at " & Time
Err.Raise 9987 , , "No CUSTOMER_ORDER record found for order line (amend) " & iarray(2) & " / " & iarray(4) & " / " & iarray(5)
Call ErrHand(err.number,err.description)
else
planship = rs.Fields("PlanShip").value
rs.close
End If
dtspackagelog.writestringtolog "PlanShip (amend) set to " & planship & " at " & Time
If rs1.fields("planned_ship_date").value <> planship Then
dtspackagelog.writestringtolog "Update PlanShip from " & rs1.fields("planned_ship_date").value & " to " & planship & " at " & Time
' Do i need a rs1.close here
set rs1 = cn1.execute("UPDATE Add_Info set planned_ship_date = '" & planship & "' where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If Err Then
' An error occurred so process
Call ErrHand(err.number,err.description)
End If
End If
End If
End If
dtspackagelog.writestringtolog "Finish Proc_Amend at " & Time
End Function