データの各行が更新されていない場合にエラー メッセージをテキスト ファイルに書き込みたいというコードがここにあります。私の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