0

:eek: Hi,

Im having problems in adding new records in a database connected to .net. The data type of ID in access is NUMBER. When I click SAVE it shows this error message: "Column 'ID' is constrained to be unique. Value '1' is already present."

Here is the code for SAVE..
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If inc <> -1 Then
NavigateRecords()
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("HostingDB").NewRow()
dsNewRow.Item("ID") = txtCiD.Text
dsNewRow.Item("CName") = txtCName.Text
dsNewRow.Item("PCont") = txtPCont.Text

Try
ds.Tables("HostingDB").Rows.Add(dsNewRow)
Catch ex As Exception
MsgBox(ex.Message)
End Try

da.Update(ds, "HostingDB")
MsgBox("New Record added to the Database")
End If
End Sub


Thanks in advance!

2
Contributors
1
Reply
5
Views
10 Years
Discussion Span
Last Post by sushanth
0

Hi,
As the Column 'ID' is unique, before inserting giv a check for existing ID and proceed with inserting to the database. or else create the ID as autonumber and insert the rest columns. so with this, access with increment the ID field with 1 and you can add the column without any error.

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.