我在这里有代码,如果每行数据没有更新,我想在文本文件中写入错误消息。我能知道我的 try..catch 块是对还是错?
For rCnt = 3 To 4
Empno = xlRange.Cells(rCnt, 1).Value
totalhrs = xlRange.Cells(rCnt, 3).Value 'workhr
latehr = xlRange.Cells(rCnt, 4).Value 'latehr
earlyhr = xlRange.Cells(rCnt, 5).Value 'earlyhr
norOT = xlRange.Cells(rCnt, 6).Value 'nor OT
holOT = xlRange.Cells(rCnt, 7).Value 'hol ot
otherOT = xlRange.Cells(rCnt, 8).Value 'other ot
attend = xlRange.Cells(rCnt, 9).Value 'attendace
absent = xlRange.Cells(rCnt, 10).Value 'absent
mc = xlRange.Cells(rCnt, 11).Value 'leave
sCommand = "UPDATE paytran.dbf SET paytran.workhr = " & totalhrs & ", paytran.latehr = " & latehr & ", paytran.earlyhr = " & earlyhr & ", paytran.ot1 = " & norOT & ", paytran.ot2 = " & holOT & ", paytran.ot3 = " & otherOT & ", paytran.dw = " & attend & ", paytran.ab = " & absent & ", paytran.mc = " & mc & " , paytran.payyes = 'Y' WHERE paytran.empno == '" & Empno & "'"
dBaseCommand = New OleDbCommand(sCommand, dBaseConnection)
Try
retVal = dBaseCommand.ExecuteNonQuery()
Catch ex As IOException
'To_WriteAudit("Error", ex.Message.ToString()) 'here my catch block that write the file..
End Try
Next rCnt
Public Sub To_WriteAudit(ByVal pstrAction As String, ByVal pstrErrorDes As String)
Dim pathlf As String
pathlf = "C:\logfile.txt"
Dim fswAuditLog As StreamWriter
fswAuditLog = New StreamWriter(pathlf, True)
fswAuditLog.WriteLine("Write the exception here")
fswAuditLog.Flush()
fswAuditLog.Close()
End Sub