Concurrency Exception and Enforce Contraints problem

L

Lee Clements

Hi all,

I am working through a example walkthrough at
http://msdn2.microsoft.com/en-us/library/ms171936(VS.80).aspx to try and
understand how to deal with concurrency issues. The only difference is that
I'm using my own tables, etc. I have used the wizards to create all of the
components and have a datagrid that displays a list of staff records. The
grid also uses two comboboxes linked to two seperate tables within the
dataset to display office rather than office_id and also their
permissions_level.

Everything works ok and when I force a concurrency exception the code fails
when I try to obtain the original datarow by calling Fill on the
TableAdapter.

Private Function GetCurrentRowInDB(ByVal RowWithError As
JPAJobSchedulerDataSet.tblStaffRow) _
As JPAJobSchedulerDataSet.tblStaffRow

Me.TblStaffTableAdapter.Fill(TempCustomersDataTable)

Dim currentRowInDb As JPAJobSchedulerDataSet.tblStaffRow = _
TempCustomersDataTable.FindBystaff_id(RowWithError.staff_id)

Return currentRowInDb
End Function

The error is a contraints error, but I cannot work out which row or
contraint is generating the exception. If I clear the exceptions on the temp
table TempCustomersDataTable before calling the Fill method, then the
exception is bypassed but I then get a problem on the "FindBystaff_id"
method because the primary key is then missing.

Can anyone point me in the right direction to begin debugging this code? I
have tried to look at the exception in more detail with the helpers but I
cannot see anything obvious.

Many thanks in advance for your help
Lee
 
L

Lee Clements

Ok, just in case anybody was interested I have resolved the problem by
firstly clearing the constraints and then adding the primary key back to the
table, see below:

Private Function GetCurrentRowInDB(ByVal RowWithError As
JPAJobSchedulerDataSet.tblStaffRow) _
As JPAJobSchedulerDataSet.tblStaffRow

TempCustomersDataTable.Constraints.Clear()
Me.TblStaffTableAdapter.Fill(TempCustomersDataTable)

Dim keys(0) As DataColumn
keys(0) = TempCustomersDataTable.Columns("staff_id")

TempCustomersDataTable.PrimaryKey = keys

Dim currentRowInDb As JPAJobSchedulerDataSet.tblStaffRow = _
TempCustomersDataTable.FindBystaff_id(RowWithError.staff_id)

Return currentRowInDb
End Function

I am not sure if this is the correct way to handle this but it works. If
anyone has any ideas thoughts or other ideas on this I would be pleased to
hear them.

Thanks
Lee
 

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

Top