0

I'm building an applications that uses an access database. I can successfully add a new row, but when i add a second row i get the error:

System.Data.ConstraintException occurred in System.Data.dll

Column "Name" is constrained to be unique.  Value "katy" is already present.

There is only 1 record in the database with Name value Kevin, so the value katy is not present.

Here is the code:

Public Class Checkin
Dim checkin As Camping_databaseDataSet.CampingRow
Private Sub Checkin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    arrivalpick.Text = DateAndTime.Now
    checkin = Camping_databaseDataSet.Camping.NewCampingRow()
    CampingTableAdapter.Fill(Camping_databaseDataSet.Camping)
    Camping_databaseDataSet.Camping.NewCampingRow()
End Sub

Private Sub BtnSaveRecord_Click(sender As Object, e As EventArgs) Handles BtnSaveRecord.Click
    checkin.ArrivalDate = CDate(arrivalpick.Text)
    checkin.City = txtcity.Text
    If chkconnection.Checked = True Then
        checkin.Connection = True
    Else
        checkin.Connection = False
    End If
    checkin.Country = txtcountry.Text
    checkin.Name = txtname.Text
    checkin.NoAdults = adultcount.Text
    checkin.NoCaravan = caravancount.Text
    checkin.NoChildren = childcount.Text
    checkin.NoDogs = dogcount.Text
    checkin.NoGrey = greycount.Text
    checkin.NoMobilhome = mobilhomecount.Text
    checkin.NoShowercoins = showercoincount.Text
    checkin.NoTent = tentcount.Text
    checkin.NoTransport = transportcount.Text
    checkin.NoYellow = yellowcount.Text
    checkin.Street = txtstreet.Text
    checkin.EndEdit()
    Camping_databaseDataSet.Camping.Rows.Add(checkin)
    Me.CampingTableAdapter.Update(Me.Camping_databaseDataSet)
    Camping_databaseDataSet.Camping.AcceptChanges()
    End Sub
End Class

What am i doing wrong?

Gridview

DB connecyion

17
  • the error means what it says. Your db has 'Name' defined as a unique value, so only one row with John or Mary or Jose can exist in that table. Commented Sep 8, 2014 at 12:00
  • @Plutonix , that's the thing. There only is 1 row in the table. With name Kevin. There are no other rows. Commented Sep 8, 2014 at 12:39
  • make sure you are looking at the same DB that the app is writing to Commented Sep 8, 2014 at 12:46
  • @Plutonix I'm sure of that, there only is 1 row in the table. With name Kevin. There are no other rows. Commented Sep 8, 2014 at 13:08
  • @Plutonix i've added an image with a grid view, as you can see, there is only one row. there is one strange thing, if i add a row in the program (when there are no rows in the DB) it works and the row is added in the gridview. but, if i close the program and open the DB file with access, the DB is empty. if i then reopen the program, all the added data is gone to (but if i do not open the DB file with access, the data stays in the DB) Commented Sep 8, 2014 at 13:18

1 Answer 1

0

The problem was in the table itself.

I had a column called "name", this was a reserved object in Access.

By changing it, the problem was solved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.