M
MadCrazyNewbie
Hello Everyone,
I have a rather anoying problem, an don`t know how to sort it.
I ahve a app and when I try and load my Datasets in to it it tells me
"Failed to Enable Constraints. One or More Rows contain values violating
non-null, unique, or foreign-key constraints."
Here is my code:
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancel.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").CancelCurrentEdit()
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
If (Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Count > 0) Then
Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").RemoveAt(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position)
Me.dsArcirisUsers_PositionChanged()
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Try
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
Try
mlLoading = True
Me.LoadDataSet()
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavFirst.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position = 0
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.dsArcirisUsers.Tables("ArcirisUsers").Rows.Count - 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavPrev.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position - 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavNext.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position + 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub dsArcirisUsers_PositionChanged()
If Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position <> -1 Then
Me.cboArcirisUsersPrimarySite.SelectedValue =
dsArcirisUsers.ArcirisUsers.Rows(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position).Item("SitesID")
End If
Me.lblNavLocation.Text = (((Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position + 1).ToString + " of ") +
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Count.ToString)
End Sub
Public Sub UpdateDataSet()
Dim objArcirisUsersDataSetChanges As dsArcirisUsers = New dsArcirisUsers()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
objArcirisUsersDataSetChanges = CType(dsArcirisUsers.GetChanges,
dsArcirisUsers)
If (Not (objArcirisUsersDataSetChanges) Is Nothing) Then
Try
Me.UpdateDataSource(objArcirisUsersDataSetChanges)
dsArcirisUsers.Merge(objArcirisUsersDataSetChanges)
dsArcirisUsers.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
End Sub
Public Sub LoadDataSet()
Dim objArcirisUsersDataSetTemp As dsArcirisUsers
objArcirisUsersDataSetTemp = New dsArcirisUsers()
Try
Me.FillDataSet(objArcirisUsersDataSetTemp)
Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try
Try
dsArcirisUsers.Clear()
dsArcirisUsers.Merge(objArcirisUsersDataSetTemp)
Catch eLoadMerge As System.Exception
Throw eLoadMerge
End Try
End Sub
Public Sub UpdateDataSource(ByVal ChangedRows As dsArcirisUsers)
Try
If (Not (ChangedRows) Is Nothing) Then
Me.odcMainMenu.Open()
odaArcirisUsers.Update(ChangedRows)
odaSites.Update(ChangedRows)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.odcMainMenu.Close()
End Try
End Sub
Public Sub FillDataSet(ByVal dataSet As dsArcirisUsers)
dataSet.EnforceConstraints = False
Try
Me.odcMainMenu.Open()
Me.odaArcirisUsers.Fill(dataSet)
Me.odaSites.Fill(dataSet)
Catch fillException As System.Exception
Throw fillException
Finally
dataSet.EnforceConstraints = True
Me.odcMainMenu.Close()
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles cboArcirisUsersPrimarySite.SelectedIndexChanged
If Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position <> -1 And Not
mlLoading Then
dsArcirisUsers.ArcirisUsers.Rows(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position).Item("SitesID") =
Me.cboArcirisUsersPrimarySite.SelectedValue
End If
End Sub
Sorry it so long
Regards
MCN
I have a rather anoying problem, an don`t know how to sort it.
I ahve a app and when I try and load my Datasets in to it it tells me
"Failed to Enable Constraints. One or More Rows contain values violating
non-null, unique, or foreign-key constraints."
Here is my code:
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancel.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").CancelCurrentEdit()
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
If (Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Count > 0) Then
Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").RemoveAt(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position)
Me.dsArcirisUsers_PositionChanged()
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Try
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
Try
mlLoading = True
Me.LoadDataSet()
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavFirst.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position = 0
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.dsArcirisUsers.Tables("ArcirisUsers").Rows.Count - 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavPrev.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position - 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavNext.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position =
(Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position + 1)
Me.dsArcirisUsers_PositionChanged()
End Sub
Private Sub dsArcirisUsers_PositionChanged()
If Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position <> -1 Then
Me.cboArcirisUsersPrimarySite.SelectedValue =
dsArcirisUsers.ArcirisUsers.Rows(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position).Item("SitesID")
End If
Me.lblNavLocation.Text = (((Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position + 1).ToString + " of ") +
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Count.ToString)
End Sub
Public Sub UpdateDataSet()
Dim objArcirisUsersDataSetChanges As dsArcirisUsers = New dsArcirisUsers()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
objArcirisUsersDataSetChanges = CType(dsArcirisUsers.GetChanges,
dsArcirisUsers)
If (Not (objArcirisUsersDataSetChanges) Is Nothing) Then
Try
Me.UpdateDataSource(objArcirisUsersDataSetChanges)
dsArcirisUsers.Merge(objArcirisUsersDataSetChanges)
dsArcirisUsers.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
End Sub
Public Sub LoadDataSet()
Dim objArcirisUsersDataSetTemp As dsArcirisUsers
objArcirisUsersDataSetTemp = New dsArcirisUsers()
Try
Me.FillDataSet(objArcirisUsersDataSetTemp)
Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try
Try
dsArcirisUsers.Clear()
dsArcirisUsers.Merge(objArcirisUsersDataSetTemp)
Catch eLoadMerge As System.Exception
Throw eLoadMerge
End Try
End Sub
Public Sub UpdateDataSource(ByVal ChangedRows As dsArcirisUsers)
Try
If (Not (ChangedRows) Is Nothing) Then
Me.odcMainMenu.Open()
odaArcirisUsers.Update(ChangedRows)
odaSites.Update(ChangedRows)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.odcMainMenu.Close()
End Try
End Sub
Public Sub FillDataSet(ByVal dataSet As dsArcirisUsers)
dataSet.EnforceConstraints = False
Try
Me.odcMainMenu.Open()
Me.odaArcirisUsers.Fill(dataSet)
Me.odaSites.Fill(dataSet)
Catch fillException As System.Exception
Throw fillException
Finally
dataSet.EnforceConstraints = True
Me.odcMainMenu.Close()
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles cboArcirisUsersPrimarySite.SelectedIndexChanged
If Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position <> -1 And Not
mlLoading Then
dsArcirisUsers.ArcirisUsers.Rows(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position).Item("SitesID") =
Me.cboArcirisUsersPrimarySite.SelectedValue
End If
End Sub
Sorry it so long
Regards
MCN