Hi, i am trying to write a code to Insert new records, and while doing so, want to check if the ID already exist. Finding it difficult to code. here's my code.

Dim ic As Integer
        ic = Val(Me.TextBox1.Text) ' ic for ItemCode

Dim foundRow As DataRow = ds.Tables("ITEM").Rows.Find(ic)
        If foundRow IsNot Nothing Then
            'MsgBox(foundRow(1))
             MsgBox("Duplicate Value. Please enter a new ID")
            Exit Sub
        End If
        frmEdit_Items.ITEMTableAdapter.Insert(Me.TextBox1.Text, Me.TextBox2.Text, Me.TextBox3.Text)
        frmEdit_Items.ITEMTableAdapter.Fill(frmEdit_Items.KSDBDataSet.ITEM)
        frmEdit_Items.ITEMTableAdapter.Update(frmEdit_Items.KSDBDataSet.ITEM)

Sorry, and i also get this Error message when i execute this:

"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."