I am am experience Mainframe programmer, but new to SQL-Server & learning vb.net so I realise that this is probably very basic ...

I have a DataTable called MailTypes which contains 2 Columns, the ID & the Name.

I have a DataTable called Leagues which contains a lot of Columns, one of which is a Foreign Key linked to the MailTypes Primary Key, which I want to access once for every Row in the MailTypes Table & use the MailType Name each time through.

What is the best way to do this ?

As an example ...

MailTypeID ... MailTypeName
     1     ...    Pass 1
     2     ...    Pass 2
     3     ...    Pass 3

LeagueID ... LeagueName ... MailTypeID
     1   ...   League1  ...    2
     2   ...   League2  ...    3
     3   ...   League3  ...    2
     4   ...   League4  ...    1
     5   ...   League5  ...    1
     6   ...   League6  ...    3

My Output (after formatting) will be

Pass 1
League4
League5

Pass2
League1
League3

Pass3
League2
League6

If you do

SELECT MailTypeName, LeagueName
  FROM MailTypes AS M INNER JOIN Leagues AS L
    ON M.MailTypeID = L.MailTypeID
 ORDER BY MailTypeName

you get

Pass 1  League4
Pass 1  League5
Pass 2  League1
Pass 2  League3
Pass 3  League2
Pass 3  League6

which, with a little formatting, is what you want.

Sorry, I've been avoiding this program for the past couple of days, I was so frustrated ... I'll try this tormorrow & see how I get on, thank you ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.