PC Review


Reply
Thread Tools Rate Thread

Relationships using multi-column key..

 
 
Graham Blandford
Guest
Posts: n/a
 
      21st May 2004
Hi all,

Can anyone assist me? VB6er trying to delve into the world of .NET...

I have inherited a poorly designed database (access).. that uses
multi-column keys to determine parent-child relationships. Could anyone
suggest how I can handle this using a relation in VB.NET.

E.g.

Table "Area"

Year
AreaId
AreaName

has a primary key of Year and AreaId,

Table "Section" has child records of "Area";

Year
AreaId
Section
Section Name

Therefore, child records are selected as those that have the same Year and
AreaId ..

If anyone can help I'd very much appreciate it.

Thanks,
Graham Blandford


 
Reply With Quote
 
 
 
 
Val Mazur
Guest
Posts: n/a
 
      21st May 2004
Hi,

What do you need, to create joined SQL statement or set relations between
the datatables inside of the dataset?

--
Val Mazur
Microsoft MVP


"Graham Blandford" <(E-Mail Removed)> wrote in message
news:U1drc.36579$(E-Mail Removed)...
> Hi all,
>
> Can anyone assist me? VB6er trying to delve into the world of .NET...
>
> I have inherited a poorly designed database (access).. that uses
> multi-column keys to determine parent-child relationships. Could anyone
> suggest how I can handle this using a relation in VB.NET.
>
> E.g.
>
> Table "Area"
>
> Year
> AreaId
> AreaName
>
> has a primary key of Year and AreaId,
>
> Table "Section" has child records of "Area";
>
> Year
> AreaId
> Section
> Section Name
>
> Therefore, child records are selected as those that have the same Year and
> AreaId ..
>
> If anyone can help I'd very much appreciate it.
>
> Thanks,
> Graham Blandford
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
Hi Graham,

You mean something as this?

Cor
\\\
Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n AND A.n = 10"
Dim Conn As New OleDbConnection(connString)
Dim da As New OleDbDataAdapter(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
Dim drlA As New DataRelation _
("AA", ds.Tables("A").Columns("A.n"), _
ds.Tables("B").Columns("B.n"))
ds.Relations.Add(drlA)
Dim dv As New DataView(ds.Tables("A"))
DataGrid1.DataSource = dv
DataGrid1.Expand(-1)
///


 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      21st May 2004
Hi Graham:

Cor and Val already answered it for you but i'd like to add one thing
semi-related if I may. If you look at Cor's example, that's how you join
table using a DataRelation w/ an untyped dataset.
This gives you a tremendous amount of power and flexibility and allows you
to navigate related records and perfom master-detail binding and all of that
good stuff. This is the crux of what you asked.

As an aside though, if you want to create composite keys, so that you can
find/navigate on multiple fields that may comprise a key, you can set the
PrimaryKey property of a datatable
http://www.knowdotnet.com/articles/dataviewsort.html . You should note
though that the PrimaryKey property takes an ARRAY of datacolumns, even if
that array contains just one item. It's a common mistake to set the
property to the column itself instead of an array.

Adding a Composite Key does nothing in and of itself for the problem you
originally asked about but it does allow you to enforce integrity rules and
use finds on the PrimaryKey field(s). Combined with using a dataRelation as
Cor illustrated can really allow you to do some cool stuff.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"Graham Blandford" <(E-Mail Removed)> wrote in message
news:U1drc.36579$(E-Mail Removed)...
> Hi all,
>
> Can anyone assist me? VB6er trying to delve into the world of .NET...
>
> I have inherited a poorly designed database (access).. that uses
> multi-column keys to determine parent-child relationships. Could anyone
> suggest how I can handle this using a relation in VB.NET.
>
> E.g.
>
> Table "Area"
>
> Year
> AreaId
> AreaName
>
> has a primary key of Year and AreaId,
>
> Table "Section" has child records of "Area";
>
> Year
> AreaId
> Section
> Section Name
>
> Therefore, child records are selected as those that have the same Year and
> AreaId ..
>
> If anyone can help I'd very much appreciate it.
>
> Thanks,
> Graham Blandford
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I place a multi column sub rpt in a multi column report? =?Utf-8?B?R09T?= Microsoft Access Reports 5 25th Aug 2006 09:18 PM
multi relationships yaniv d Microsoft Access 6 29th May 2006 03:17 PM
Relationships using multi-column key.. Graham Blandford Microsoft Dot NET 3 21st May 2004 09:49 PM
Relationships using multi-column key.. Graham Blandford Microsoft VB .NET 3 21st May 2004 09:49 PM
Multi Relationships John Microsoft Access Database Table Design 1 17th May 2004 05:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:36 PM.