Anoying Problem

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
 
M

MadCrazyNewbie

Hey Cor

Me.cboArcirisUsersPrimarySite.SelectedValue =
dsArcirisUsers.Sites.Rows(Me.BindingContext(dsArcirisUsers,
"Sites").Position).Item("SitesID")

It tells me on this line of code now that:

"An unhandled exception of type 'System.Exception' occurred in
system.windows.forms.dll. Additional information: Can't set the
SelectedValue in a ListControl with empty ValueMember."

Many Thanks
MCN
 
C

CJ Taylor

Simon?

Why are you changing names?

Anyways, didn't you get my email? You weren't setting your value member
property on your combo box, thats why your throwing the exception.

-CJ
 
C

CJ Taylor

Also, I lost your email address... I had a problem with my development
machine at home, long story short, PST file is gone, which has all my
email...

-CJ
 
M

MadCrazyNewbie

Doh,

Sorry i`ve just relised i ain`t selected the propery for the CBO:(

Thanks All
 
R

Richard

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

Hi MCN,

You post was just a garbled dump by the time it reached my screen so
im going to be lazy and not troll through all of it. Sorry but it's a
real mess at this end. Im picking the problem is in the block above
anyway.

Everything in your other methods is wrapped in non specific exception
handlers( which isn't a good idea), so it couldn't be where your
getting a break error.

It's hard to say without stepping through and seeing what gets data
does/does not get into your dataset but the following line i suspect
is the villian
dataSet.EnforceConstraints = True

You do this in finally. Bad idea. You should do this in the try block
before catch. This will be why your error, i assume is breaking your
app, its not being caught. Finally is a clean up stage of the
exception handler, you shouldn't use it to perform more work.

My pick is the data from your db is mangled. Maybe your getting data
from one table that has a foriegn key constraint to another table in
your ds that isn't getting filled? So when you enabled constraints it
gets all ratty and doesn't want to play anymore.

Maybe your db isn't enforcing the same constraints as your ds?
Poor/outdated db design?

Theres an arm full of potential reasons. You need to step into it and
have a look. Do you even want these constraints to be applied? If for
some reason it doesn't matter just dont do this

dataSet.EnforceConstraints = True


Step into with the debugger after putting that line into the try area
and see what happens.

hth

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dataset NOT Updating 15
Going Crazy nearly 2 weeks 1
DataRow - How To? 13
Litle Problem Help Plz 2
Judt a quick Check 2
Database Records Represantation Problem ? ? ? 1
DBNUL Errors Continued 4
Debugging Error 1

Top