rows.add访问数据库vb.net

时间:2014-09-08 11:14:08

标签: database vb.net

我正在构建使用访问数据库的应用程序。 我可以成功添加一个新行,但是当我添加第二行时,我收到错误:

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

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

数据库中只有1条记录,名称值为Kevin,因此值katy不存在。

以下是代码:

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

我做错了什么?

Gridview

DB connecyion

1 个答案:

答案 0 :(得分:0)

问题在于表格本身。

我有一个名为" name"的列,这是Access中的保留对象。

通过改变它,问题就解决了。