Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / January 2007

Tip: Looking for answers? Try searching our database.

Designer creating duplicate DataRelation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Glenn - 15 Jan 2007 14:43 GMT
Hi

I've created a typed DataSet called MembershipDataSet.  MembershipDataSet
contains a baked-in DataRelation between two tables which gets created in
the constructor and added to the base class DataRelationCollection.

In VS forms I drag the MembershipDataSet component onto the form.  Then I
add a binding source which uses the MembershipDataSet instance as its
DataSource and the master table name as the DataMember.  I then drag a
DataGridView onto the form and set the DataSource property to the binding
source.

Then I add a second binding source and set the DataSource to the first
binding source.  The DataMember is set to the name of the DataRelation which
is listed in the Properties window.  I then drag another DataGridView for
the child table and set its DataSource to the second binding source
instance.

So far, so good.

When I run the application I get a 'DuplicateNameException' because the
designer has created and added a new DataRelation with the same name as the
MembershipDataSet instance existing relationship.  Catch 22 - If I don't
create the DataRelation in the MembershipDataSet then I won't see it in the
designer, in which case I'd have to create it by hand which, defeats the
purpose of using the visual designer to work with databinding.

I realise I could do the necessary to get everything working just as I'd
like it to by hand, but I'm curious as to why it tries to create the
DataRelation even though one already exists.

Any ideas where it's/I'm going wrong?

TIA

Glenn
Bart Mermuys - 15 Jan 2007 23:54 GMT
Hi,

> Hi
>
[quoted text clipped - 28 lines]
>
> Any ideas where it's/I'm going wrong?

Not really, seems very strange.  AFAIK the designer can't/won't add
relations to a typed DataSet relational binding or not.  I also tried a
similar setup to what you described and can't reproduce the problem.

When you get the Exception, does the stack trace (debug) doesn't provide any
meaningfull info (like where it originated )?

How do you know it's the designer that's adding the relation ? Did you look
at the designer generated code (InitializeComponent inside the designer.cs
file) ?

HTH,
Greetings

> TIA
>
> Glenn
RobinS - 16 Jan 2007 06:17 GMT
> Hi,
>
[quoted text clipped - 36 lines]
> relations to a typed DataSet relational binding or not.  I also tried
> a similar setup to what you described and can't reproduce the problem.

Yes, the designer *does* do this if the relationship is defined in
your database schema. Create a strongly typed dataset with both the
Customers and Orders tables from Northwind in it; you will see
the relation between them drawn automatically.

My question for OP is this: is the MembershipDataSet's "baked-in"
relation coming from the designer-generated code? Or did he add it
programmatically or to the DataSet in the designer? Is there a
datarelation defined in the database like a foreign key? If there
is a foreign key, then there is a data relation.

Robin S.
Glenn - 16 Jan 2007 10:17 GMT
Responses inline...

>> Hi,
>>
[quoted text clipped - 44 lines]
> relation coming from the designer-generated code? Or did he add it
> programmatically or to the DataSet in the designer?

I should have mentioned that the MembershipDataSet is generated using
CodeDom, but not by Visual Studio, so essentially the DataRelation was added
programmatically in the constructor.

>Is there a datarelation defined in the database like a foreign key? If
>there
> is a foreign key, then there is a data relation.

There are no foreign-key constraints in the source database, yet.  The only
relationship is the programmatic DataRelation in the MembershipDataSet.

As I said, I should've mentioned that all the data-related types in my
solution have been generated using code that I wrote.  And there lies my
concern, I've probably missed something.

BTW I'm not a glutton for punishment.  The reason for creating data access
code this way is that ODP.NET and Oracle DB Lite don't work, or at least
don't work very well with the DataSet Designer in VS.

Thanks for all replies

Glenn
Bart Mermuys - 16 Jan 2007 11:56 GMT
Hi,

> Responses inline...
>
[quoted text clipped - 63 lines]
> solution have been generated using code that I wrote.  And there lies my
> concern, I've probably missed something.

Yes, you should have mentioned that :-) since the problem doesn't occure
with the VS generated typed dataset , big chances are you've made some
mistake building your own typed DataSet.

It's also possible that something is wrong with your typed dataset that is
making the WinForm designer add the DataRelation another time.

A quick look at the VS generated typed DataSet did reveal some interesting
code that prevents the WinForm designer from serializing the DataRelations
(adding code inside InitializeComponent).   The WinForm  designer shouldn't
serialize the DataRelations since they are default ones build inside the
constructor.

public new System.Data.DataRelationCollection Relations
{
get {  return base.Relations;  }
}

protected override bool ShouldSerializeRelations()
{
 return false;
}

But the same thing is done for DataTables though you don't mention anything
about duplicated tables...

HTH,
Greetings

> BTW I'm not a glutton for punishment.  The reason for creating data access
> code this way is that ODP.NET and Oracle DB Lite don't work, or at least
[quoted text clipped - 3 lines]
>
> Glenn
Glenn - 16 Jan 2007 13:04 GMT
Bart

I hadn't overridden ShouldSerializeRelations.

As simple as that.

Many thanks

Glenn

> Hi,
>
[quoted text clipped - 102 lines]
>>
>> Glenn
Bart Mermuys - 16 Jan 2007 11:25 GMT
Hi,

>> Hi,
>>
>>> Hi

[snipped]
>>> I realise I could do the necessary to get everything working just as I'd
>>> like it to by hand, but I'm curious as to why it tries to create the
[quoted text clipped - 10 lines]
> Customers and Orders tables from Northwind in it; you will see
> the relation between them drawn automatically.

Yes, the DataSet designer can add relations but that's not a or the problem.
But with designer i only meant the WinForm designer, the WinForm designer
shouldn't add a relations to a typed dataset.

Greetings

> My question for OP is this: is the MembershipDataSet's "baked-in"
> relation coming from the designer-generated code? Or did he add it
[quoted text clipped - 3 lines]
>
> Robin S.
RobinS - 16 Jan 2007 20:33 GMT
> Hi,
>
[quoted text clipped - 24 lines]
>
> Greetings

Gotcha. Thanks for clarifying.
Robin S.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.