data relation already exist

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
159
Programming Experience
1-3
Hi,

I have created a data relation between 2 tables and everything works ok but when I click on a button to reload the form I get datarealtion error dataset relation already exists.

is there any way to test if data relation already exist before assigning it...code is as follows;

VB.NET:
relation = New DataRelation("RelPayPeriod", ds.Tables("VwHHHoursAL").Columns("PayPeriod"), ds.Tables("VwHHWorkedHours").Columns("PayPeriod"), False)
                Me.ds.Relations.Add(relation) 
                bs2.DataSource = bs1
                bs2.DataMember = "RelPayPeriod"
                Me.BindingNavigator2.BindingSource = bs2
 
I don't want to discourage you or anyone else from using forums like this one but they should be places that you use only after you've already tried to find the answer for yourself. If you haven't used the Help menu in VS then you haven't really tried.

In this case, you should have used the Help menu or even just the F1 key to open the documentation for the DataSet.Relations property and then followed the link for the DataRelationCollection class and found that it has a Contains method that allows you to determine whether the collection contains a DataRelation with a specific name.

That's about 20 seconds work. ALWAYS read the relevant documentation first when you have a question. You won't always find what you need or understand what you find but the more you use it the more often you you will and this case is a perfect example of how easy it can be to find answers.
 
Back
Top