Results 1 to 3 of 3

Thread: Need help with error handling

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Need help with error handling

    Hello Guys,

    I have database one of the fields is set as primary key? When somebody try‘s to add duplicate value of cause gets an error. Is there a way to capture database duplicate key error so I can display message box when this particular error occurs.

    Code:
    Public Sub Modify(ByVal SqlStr As String, ByVal OleDbConnection1 As OleDbConnection)
            Dim oledbMommand As OleDbCommand
            oledbMommand = New OleDbCommand(SqlStr, OleDbConnection1)
    
            Try
                OleDbConnection1.Open()
                oledbMommand.ExecuteNonQuery()
            Catch ex As Exception
                MsgBox(ex.ToString)
            Finally
                OleDbConnection1.Close()
            End Try
    
        End Sub
    Thank you.

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    Code:
    Public Sub Modify(ByVal SqlStr As String, ByVal OleDbConnection1 As OleDbConnection)
            Dim oledbMommand As OleDbCommand
            oledbMommand = New OleDbCommand(SqlStr, OleDbConnection1)
    
            Try
                OleDbConnection1.Open()
                oledbMommand.ExecuteNonQuery()
    
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
    
            Catch oledbEx as OleDbException
                MessageBox.Show(oledbEx.ToString)
    
            Finally
                OleDbConnection1.Close()
    
            End Try
    
        End Sub

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I like how you snuck the MsgBox to MessageBox.Show change in there.... lol

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width