473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Relationships using multi-column key..

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
Jul 21 '05 #1
3 1369
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" <gr**************@sympatico.ca> wrote in message
news:U1********************@news20.bellglobal.com. ..
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

Jul 21 '05 #2
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)
///
Jul 21 '05 #3
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" <gr**************@sympatico.ca> wrote in message
news:U1********************@news20.bellglobal.com. ..
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

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Megan | last post by:
Hi Everybody- I know that this is a really, really long post, but I wanted to try to give you as much background as possible. So here's a quick overview of the issues I'm asking for help with:...
49
by: Mal | last post by:
Hi, As I gain knowledge through a lot of trial, error, and usenet posts.. I have a potentially odd question. I am using a commercial access application. It is a front-end / back...
2
by: Max | last post by:
Hi. I really hope someone can help me. Going slowly insane with this problem. I have a two Access 2000 databases. One is the backend containing tables and some admin queries. The other is the...
3
by: GGerard | last post by:
Hello Does anyone know if it is possible with Access 2000 to create relationships between tables using code? Thanks G.Gerard
2
by: Gandalf | last post by:
I'm creating relationships between tables using VBA and ADOX. I can create one-to-one relationships with an inner join, but I can't figure out how to create these relationships with an outer join...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
13
by: ARC | last post by:
Hello all, Prior to going live with my app, I have questions on relationships theory. My prior app was done in Access 97, and I did NOT use relationships at all. I have 65 tables in my...
8
by: Phil Stanton | last post by:
I have a FE, BE database on my home computer and a duplicate on the office computer. Both use Ak2 on Windows XP. The one at home appears normal. The BE consists of about 50 tables with numerous...
4
by: sloney | last post by:
Hello, I have approximately 20 mdb's that have the same schema but all have different data for different geographic locations. There are a plethora of tables and relationships (to be built). I...
1
by: keydrive | last post by:
Hi, I am creating a view of several database tables in SQL. This particular view joins five tables to retrieve the necessary data. One of the tables includes multiple values for the primary in a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.