Member Avatar for b1izzard
b1izzard

I had Bind the Two Textboxes with fields Company Name and Interview Date from Database1. I want to prevent inserting the records into Database2 when the same value exists in Both Database.

My problems are in enabling and disabling the insert button during record navigation and placing the below piece of code in which event of the Binding navigation control?

Try
            Dim con As New OleDb.OleDbConnection
            Dim cmd As OleDbCommand
            Dim sql As String
            Dim dr As OleDbDataReader

            'initialize the connection string
            con.ConnectionString = _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Resources\login.mdb"
            'open the connection
            con.Open()
            sql = "Select [Company Name],[Interview Date] From studentprofiler"
            cmd = New OleDbCommand(sql, con)
            dr = cmd.ExecuteReader()
            If (dr.HasRows) = False Then
                Exit Sub
            Else
                While (dr.Read())
                    If (TextBox1.Text = dr(0).ToString() And (TextBox2.Text = dr(1).ToString)) Then
                       insertButton.Enabled = False
                    End If
                End While
            End If
            cmd = Nothing
            'close the connection
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, Me.Text)
End Try

Any idea?