Related Tables

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hello all:

I have a few questions regarding ADO.NET data access:

1. I have a DataSet that gets populated w/several tables,
but I would like to display a certain column in one of
those tables by pulling the related records from another
table. To put this clearer I have two tables in a
database, one w/shipping info and one w/drivers. They are
related by a driver id in each one. But how do I display
the shipping info w/a driver name that it pulls from the
drivers table rather than displaying the driver id?

2. What is the best way to create a connection that is
shared across multiple forms? Right now I have my main
form create a connection that I then feed to the other form
by means of a public variable. Is this how it should be done?

Thanks a bunch,

John
 
1. Create a DataRelation locally...http://www.c-
sharpcorner.com/database/DataRelationVK.asp (there's
another good example on MSDN). In your control, you can
set the DisplayMember and ValueMember....so your
displaymember would be the name, the valuemember would be
the id this article covers it in depth...
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vstechart/html/vbtchNavigatingMultipleRelatedTablesIn
ADONETDataset.asp


As far as 2 goes, you can use a Config file to store the
connectionstring for instance, and instantiate a
connection each time you need one. Or, if you have to use
the same connection, create a Sealed Single Instance class
and have a static property of type connection (as long as
the property is static, you don't necessarily have to use
Sealed Single Instance, that's a matter of taste on my
part).

When Form1 loads, call a function to instantiate the
connection. you can reference it anywhere in the app
afterward by ObjectName.Instance.ConnectionPropertyName.

Let me knwo if you have any questions.

Good Luck,

Bill

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
 
Back
Top