hi codeproject member, i have code here that i want to write error message in text file if each row of data is not update. can i know is it my try..catch block is right or wrong?
If triallicense = "Demo" Then
File_dbf = "C:\ddd" & Companydbf & "\paytran.dbf"
Dim ConnectionString As String = String.Empty, sCommand As String = String.Empty
Dim rCnt As Integer = 0, Empno As String, Otvalue As Integer = 0, retVal As Integer = 0, totalhrs As Integer = 0
Dim xlApp As Excel.Application = Nothing, xlWorkBook As Excel.Workbook = Nothing, xlWorkSheet As Excel.Worksheet = Nothing, xlRange As Excel.Range = Nothing
Dim latehr As Double, earlyhr As Double, norOT As Double, holOT As Double, otherOT As Double
Dim attend As Double, absent As Double, mc As Double
Dim dBaseConnection As OleDb.OleDbConnection = Nothing, dBaseCommand As OleDb.OleDbCommand = Nothing
Try
ConnectionString = "Provider=vfpoledb;Data Source=" & IO.Path.GetDirectoryName(File_dbf) & ";Collating Sequence=machine;"
dBaseConnection = New OleDb.OleDbConnection(ConnectionString)
dBaseConnection.Open()
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(xlsName)
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
xlRange = xlWorkSheet.UsedRange
For rCnt = 3 To 4
Empno = xlRange.Cells(rCnt, 1).Value
totalhrs = xlRange.Cells(rCnt, 3).Value
latehr = xlRange.Cells(rCnt, 4).Value
earlyhr = xlRange.Cells(rCnt, 5).Value
norOT = xlRange.Cells(rCnt, 6).Value
holOT = xlRange.Cells(rCnt, 7).Value
otherOT = xlRange.Cells(rCnt, 8).Value
attend = xlRange.Cells(rCnt, 9).Value
absent = xlRange.Cells(rCnt, 10).Value
mc = xlRange.Cells(rCnt, 11).Value
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 Exception
End Try
Next rCnt
xlWorkBook.Close()
xlApp.Quit()
dBaseConnection.Close()
Catch ex As System.InvalidCastException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Catch ex As OleDb.OleDbException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Catch ex As System.NullReferenceException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Finally
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End Try
End If