0

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)
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by chanthung
0

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."

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.