DataView on two DataTables

G

Guest

Hi,

Please, help. Can I create a DataView on top of more than one DataTable.
If not, how can I implement this for sorting, filtering?????
 
F

Frans Bouma [C# MVP]

Garik said:
Hi,

Please, help. Can I create a DataView on top of more than one
DataTable. If not, how can I implement this for sorting,
filtering?????

A dataview is a view on a single table. It contains the rows from the
underlying datatable matching the filter you set sorted using the
sorter you set.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
C

Cor Ligthert [MVP]

If not, how can I implement this for sorting, filtering?????
That is completely dependend from what you want, however as Frans said, a
dataview is only doing one table, therefore tell what you want, and what is
the data in your rows (and what are the relations)

Cor
 
G

Guest

For example I have two tables: Order Header and Customer, and a relation
OrderHeader.CustKey = Customer.CustKey.

So, I want to show Orders in the DataGridView, and Filter or Sort that grid
by 'Customer.CustomerName, Order.OrderDate DESC'.

Thanks.
 
C

Cor Ligthert [MVP]

Garik,

Not giving the fish I would say, that in your case I would probably do
something as filtering either using the Select or the DataView the Parent
table on the CustKeys I want and than use that to get the children. (That is
an existing method from datarow). Then you have the collection of datarows
that you want to show.

Cor
 
G

Guest

Thank you Core,

But this will not resolve my problem, because I must bind the joined data to
the DataGrid. But in your supposed case I must programatically fill the grid.

I want users would see the joined grid, and sort or filter the data (as they
do in SQL Server (e.g. Enterprise Manager).

Garik
 
B

Bart Mermuys

Hi,

Garik said:
For example I have two tables: Order Header and Customer, and a relation
OrderHeader.CustKey = Customer.CustKey.

Suppose you want to show OrderHeader fields but also
OrderHeader.Customer.Name, then you could "import" the Customer.Name into
the OrderHeader table (if you have the right relation), eg.:

OrderHeader table:
- Add column:
- Name : "CustomerName"
- Expression : "parent(fk_customer_orderheader).Name"

Once you have that, you should be able to filter and sort using the
BindingSource.

HTH,
Greetings
 
G

Guest

Thank you Bart Mermuys,

It is the exact solution I was looking for.

I tried using Expression Columns, but I don't realize when the expression is
evaluated? Is the value in the column will be changed, if I modify the row in
the Parent (Customer) table? Is the value in the column will be changed, if I
modify Foreign Key column in the Child table (OrderHeader)?

If expression is evaluated every time when I query the value in the column,
the performance will be very slow in my view.

--
Regards,
Garik Melkonyan
MCP, MCAD, MCSD .NET
 
B

Bart Mermuys

Hi,

Garik said:
Thank you Bart Mermuys,

It is the exact solution I was looking for.

I tried using Expression Columns, but I don't realize when the expression
is
evaluated?
Is the value in the column will be changed, if I modify the row in
the Parent (Customer) table? Is the value in the column will be changed,
if I
modify Foreign Key column in the Child table (OrderHeader)?

It looks like the expression is evaluated when either of the two changes you
mention happen.
If expression is evaluated every time when I query the value in the
column,
the performance will be very slow in my view.

I believe the expression is _not_ evaluated each time you access the value,
if that's what you mean.

HTH,
Greetings
 

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