My documentation shows OleDbError.SQLState to be a string.
I recommend that you turn on Strict mode in your project properties pages.
It will catch errors like this at compile-time.
--
John Saunders
John.Saunders at SurfControl.com
polynomial5d said:
OK, I've made progress thanks to you guys. Now I want to go one step
farther. I haven't cleaned up the subroutine yet, so the following snippet
is ugly. Please believe that I'll clean it up after I have it all settled.
In the try, you'll see an attempt to catch oledb exceptions. The first
one is 3022, the else is everything else. But when I have a
DBConcurrencyException, it's not being caught in the else. Later I'm
catching all exceptions, and that's where the DBConcurrencyException is
being caught.
I'd really like to know why the DB... isn't being caught in the first else clause.
polynomial5d
Private Sub btnSubmitChanges_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmitChanges.Click
Dim Check As Integer = 0
If DsDT1.HasChanges Then
DTypeOpened = False
Try
Dim intModified As Integer
intModified = daDT.Update(DsDT1.DateType)
Dim strOutput As String
strOutput = "Modified " & intModified & " item(s)"
MessageBox.Show(strOutput, "Update succeeded!",
MessageBoxButtons.OK, MessageBoxIcon.Information)
DTypeOpened = True
Dim s = ControlChars.CrLf
Catch ex As OleDbException
If ex.Errors(0).SQLState = 3022 Then
MsgBox(ex.Errors(0).Message & s & "Please try again")
Check = 1
Exit Try
Else
Dim errorMessages As String
Dim i As Integer
For i = 0 To ex.Errors.Count - 1
errorMessages += "Index #" & i.ToString() & ControlChars.CrLf _
& "Message: " & ex.Errors(i).Message & ControlChars.CrLf _
& "NativeError: " &
ex.Errors(i).NativeError & ControlChars.CrLf _
& "Source: " & ex.Errors(i).Source & ControlChars.CrLf _
& "SQLState: " &
ex.Errors(i).SQLState & ControlChars.CrLf _
& "The form will be closed"
Check = 2
Next i
MsgBox(errorMessages)
If Check = 2 Then Me.Close()
End If
Catch ex As DBConcurrencyException
MsgBox(ex.Message & s & "The dataset will be refreshed." &
s & "Then you can navigate to the row and update it again.")
DsDT1.Clear()
daDT.Fill(DsDT1, "DateType")
Exit Try
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s &
ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be
closed") '& s & ex.TargetSite)
Check = 2
Me.Close()
End Try
Else
MessageBox.Show("No changes to submit!", "SubmitChanges",
MessageBoxButtons.OK, MessageBoxIcon.Information)