Lookup columns in typed datasets

Z

Zoltan Hubai

Hi

Is there a way to create lookup columns in tables in the typed datasets?

Like

CityTable
----------
CityID
CityName

Employee
--------
EmployeeID
EmployeeName
City -> foreign key to CityTable.CityID
CityName -> lookup column, will get the value from CityTable according
the City value

First the CityTable records are loaded and then the Employee. I could do
this with SQL but that means I would load the same data 2 times and I'm
trying to lower the network usage as the lines that we are using are slow.

In expression column I was trying to use the Parent keyword but with no
luck. So is there a way to do this?
Also is there a way to create more of these lookup columns when a table
is related to more tables with foreign keys?

Thx
 
M

Miha Markic [MVP C#]

Hi Zoltan,

Yes, one way is to use expression columns. Do you have a relation defined in
your dataset? What is your syntax for CityName expression.
However, note that I wouldn't recommend using expression columns if you are
goind to edit data.
Rather, fill the field manually after you loaded data from database.
 
Z

Zoltan Hubai

Miha said:
Hi Zoltan,

Yes, one way is to use expression columns. Do you have a relation defined in
your dataset? What is your syntax for CityName expression.
However, note that I wouldn't recommend using expression columns if you are
goind to edit data.
Rather, fill the field manually after you loaded data from database.
Thx for the answers

I'm not sure how to use the expression property. According the help the
syntax is Parent.ColumnName for parent tables and Child.ColumnName for
child tables where for Child it can be used also as
Child(Relation_Name).Column but for Parent it seams there is no such way.

For lookup values I could came up with somthing like:
Parent(FK_City_Employee).CityName

where FK_City_Employee is the foreign key relation between the City and
Employee tables (City is the parent and Employee the child).

Actualy I don't want to use that field for editing but more like a
reference to user so that it has more meaning for him when the data it
displayed. Let's say i'm displaying the list of Employees in a
DataGridView and for user a City name has more meaning then the primary
key value form the City.CityID column (but it can be also a TextBox or
Label control linked to it).

I'm new to c#, I was working with Delphi till now and there where lookup
columns and it was easy to show lookup values for users from tables with
foreign key relations. In Delphi when I defined the lookup column and
changed the value of the FK field in the child table (Employee.City) all
the controls linked to the lookup column (Employee.CityName) linked to
that FK column vould change it's value automaticly.

Sorry for my weak english

Zoltan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top