PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

DataView Inner Join

 
 
=?Utf-8?B?cmFuZHkxMjAw?=
Guest
Posts: n/a
 
      20th Jun 2006
I have an orders table. Each record in the orders table contains a customer id.

I have a customer table. The primary key of each record in the customer
table is the customer id.

After getting a subset from the orders table, I need to take the customer
ids in the orders table subset, and list each record in the customer table
that has a matching customer id.

If I were in t-sql, this would be an easy inner join. In this case, I get
both complete tables in memory, and can only show the subset tables as
DataViews (or something like a DataView). I can't toss the original tables as
the user can request different views.

Any thoughts on creating a DataView in an inner join sort of way?

Thanks,
--
Randy
 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      20th Jun 2006
Hi,

Unfortunatelly you cannot do it, You have several options though.

You can create a DataView and using the RowFilter property , you can use
"in" : new DataView(....., "clientID in ( 1,2,3,4 ) );




--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"randy1200" <(E-Mail Removed)> wrote in message
news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
>I have an orders table. Each record in the orders table contains a customer
>id.
>
> I have a customer table. The primary key of each record in the customer
> table is the customer id.
>
> After getting a subset from the orders table, I need to take the customer
> ids in the orders table subset, and list each record in the customer table
> that has a matching customer id.
>
> If I were in t-sql, this would be an easy inner join. In this case, I get
> both complete tables in memory, and can only show the subset tables as
> DataViews (or something like a DataView). I can't toss the original tables
> as
> the user can request different views.
>
> Any thoughts on creating a DataView in an inner join sort of way?
>
> Thanks,
> --
> Randy



 
Reply With Quote
 
chanmm
Guest
Posts: n/a
 
      20th Jun 2006
I would suggest you to use parameterized stored procedure to retrieve the
rows to the Dataview.

chanmm

"randy1200" <(E-Mail Removed)> wrote in message
news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
>I have an orders table. Each record in the orders table contains a customer
>id.
>
> I have a customer table. The primary key of each record in the customer
> table is the customer id.
>
> After getting a subset from the orders table, I need to take the customer
> ids in the orders table subset, and list each record in the customer table
> that has a matching customer id.
>
> If I were in t-sql, this would be an easy inner join. In this case, I get
> both complete tables in memory, and can only show the subset tables as
> DataViews (or something like a DataView). I can't toss the original tables
> as
> the user can request different views.
>
> Any thoughts on creating a DataView in an inner join sort of way?
>
> Thanks,
> --
> Randy



 
Reply With Quote
 
=?Utf-8?B?cmFuZHkxMjAw?=
Guest
Posts: n/a
 
      20th Jun 2006
Thanks. Response times seem okay up to 1000 records in each table. At 10,000
records, response times take about one minute. The time get consumed by
looping through the DataRows from the second table to be put in the "in"
clause for the first table. Pointers to any other options would be
appreciated.

DataRow[] drs = dt2.Select("fk>2000");

string rowFilter = "id1 in (";

foreach (DataRow dr in drs)
{
rowFilter += dr["fk"].ToString() + ",";
}
//Note, the extra comma at the end doesn't matter
rowFilter += ")";

Console.WriteLine(rowFilter);

//dv2 = new DataView(dt1, "id1 in (10, 20,)", "id1",
DataViewRowState.CurrentRows);
dv1 = new DataView(dt1, rowFilter, "id1",
DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv1;
--
Randy


"Ignacio Machin ( .NET/ C# MVP )" wrote:

> Hi,
>
> Unfortunatelly you cannot do it, You have several options though.
>
> You can create a DataView and using the RowFilter property , you can use
> "in" : new DataView(....., "clientID in ( 1,2,3,4 ) );
>
>
>
>
> --
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
>
> "randy1200" <(E-Mail Removed)> wrote in message
> news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
> >I have an orders table. Each record in the orders table contains a customer
> >id.
> >
> > I have a customer table. The primary key of each record in the customer
> > table is the customer id.
> >
> > After getting a subset from the orders table, I need to take the customer
> > ids in the orders table subset, and list each record in the customer table
> > that has a matching customer id.
> >
> > If I were in t-sql, this would be an easy inner join. In this case, I get
> > both complete tables in memory, and can only show the subset tables as
> > DataViews (or something like a DataView). I can't toss the original tables
> > as
> > the user can request different views.
> >
> > Any thoughts on creating a DataView in an inner join sort of way?
> >
> > Thanks,
> > --
> > Randy

>
>
>

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      20th Jun 2006
Hi,

use StringBuilder instead of String for the concatenation.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"randy1200" <(E-Mail Removed)> wrote in message
news:A5742C53-1632-4CF3-81F1-(E-Mail Removed)...
> Thanks. Response times seem okay up to 1000 records in each table. At
> 10,000
> records, response times take about one minute. The time get consumed by
> looping through the DataRows from the second table to be put in the "in"
> clause for the first table. Pointers to any other options would be
> appreciated.
>
> DataRow[] drs = dt2.Select("fk>2000");
>
> string rowFilter = "id1 in (";
>
> foreach (DataRow dr in drs)
> {
> rowFilter += dr["fk"].ToString() + ",";
> }
> //Note, the extra comma at the end doesn't matter
> rowFilter += ")";
>
> Console.WriteLine(rowFilter);
>
> //dv2 = new DataView(dt1, "id1 in (10, 20,)", "id1",
> DataViewRowState.CurrentRows);
> dv1 = new DataView(dt1, rowFilter, "id1",
> DataViewRowState.CurrentRows);
> dataGridView1.DataSource = dv1;
> --
> Randy
>
>
> "Ignacio Machin ( .NET/ C# MVP )" wrote:
>
>> Hi,
>>
>> Unfortunatelly you cannot do it, You have several options though.
>>
>> You can create a DataView and using the RowFilter property , you can use
>> "in" : new DataView(....., "clientID in ( 1,2,3,4 ) );
>>
>>
>>
>>
>> --
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>>
>>
>> "randy1200" <(E-Mail Removed)> wrote in message
>> news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
>> >I have an orders table. Each record in the orders table contains a
>> >customer
>> >id.
>> >
>> > I have a customer table. The primary key of each record in the customer
>> > table is the customer id.
>> >
>> > After getting a subset from the orders table, I need to take the
>> > customer
>> > ids in the orders table subset, and list each record in the customer
>> > table
>> > that has a matching customer id.
>> >
>> > If I were in t-sql, this would be an easy inner join. In this case, I
>> > get
>> > both complete tables in memory, and can only show the subset tables as
>> > DataViews (or something like a DataView). I can't toss the original
>> > tables
>> > as
>> > the user can request different views.
>> >
>> > Any thoughts on creating a DataView in an inner join sort of way?
>> >
>> > Thanks,
>> > --
>> > Randy

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?cmFuZHkxMjAw?=
Guest
Posts: n/a
 
      20th Jun 2006
Unfortunately, I don't control the web service that provides my data. A
request has been placed...
--
Randy


"chanmm" wrote:

> I would suggest you to use parameterized stored procedure to retrieve the
> rows to the Dataview.
>
> chanmm
>
> "randy1200" <(E-Mail Removed)> wrote in message
> news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
> >I have an orders table. Each record in the orders table contains a customer
> >id.
> >
> > I have a customer table. The primary key of each record in the customer
> > table is the customer id.
> >
> > After getting a subset from the orders table, I need to take the customer
> > ids in the orders table subset, and list each record in the customer table
> > that has a matching customer id.
> >
> > If I were in t-sql, this would be an easy inner join. In this case, I get
> > both complete tables in memory, and can only show the subset tables as
> > DataViews (or something like a DataView). I can't toss the original tables
> > as
> > the user can request different views.
> >
> > Any thoughts on creating a DataView in an inner join sort of way?
> >
> > Thanks,
> > --
> > Randy

>
>
>

 
Reply With Quote
 
=?Utf-8?B?cmFuZHkxMjAw?=
Guest
Posts: n/a
 
      20th Jun 2006
Thanks for the StringBuilder pointer. Any other pointers?
--
Randy


"Ignacio Machin ( .NET/ C# MVP )" wrote:

> Hi,
>
> use StringBuilder instead of String for the concatenation.
>
>
> --
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
> "randy1200" <(E-Mail Removed)> wrote in message
> news:A5742C53-1632-4CF3-81F1-(E-Mail Removed)...
> > Thanks. Response times seem okay up to 1000 records in each table. At
> > 10,000
> > records, response times take about one minute. The time get consumed by
> > looping through the DataRows from the second table to be put in the "in"
> > clause for the first table. Pointers to any other options would be
> > appreciated.
> >
> > DataRow[] drs = dt2.Select("fk>2000");
> >
> > string rowFilter = "id1 in (";
> >
> > foreach (DataRow dr in drs)
> > {
> > rowFilter += dr["fk"].ToString() + ",";
> > }
> > //Note, the extra comma at the end doesn't matter
> > rowFilter += ")";
> >
> > Console.WriteLine(rowFilter);
> >
> > //dv2 = new DataView(dt1, "id1 in (10, 20,)", "id1",
> > DataViewRowState.CurrentRows);
> > dv1 = new DataView(dt1, rowFilter, "id1",
> > DataViewRowState.CurrentRows);
> > dataGridView1.DataSource = dv1;
> > --
> > Randy
> >
> >
> > "Ignacio Machin ( .NET/ C# MVP )" wrote:
> >
> >> Hi,
> >>
> >> Unfortunatelly you cannot do it, You have several options though.
> >>
> >> You can create a DataView and using the RowFilter property , you can use
> >> "in" : new DataView(....., "clientID in ( 1,2,3,4 ) );
> >>
> >>
> >>
> >>
> >> --
> >> --
> >> Ignacio Machin,
> >> ignacio.machin AT dot.state.fl.us
> >> Florida Department Of Transportation
> >>
> >>
> >>
> >> "randy1200" <(E-Mail Removed)> wrote in message
> >> news:7853F2B9-3284-4D92-A04F-(E-Mail Removed)...
> >> >I have an orders table. Each record in the orders table contains a
> >> >customer
> >> >id.
> >> >
> >> > I have a customer table. The primary key of each record in the customer
> >> > table is the customer id.
> >> >
> >> > After getting a subset from the orders table, I need to take the
> >> > customer
> >> > ids in the orders table subset, and list each record in the customer
> >> > table
> >> > that has a matching customer id.
> >> >
> >> > If I were in t-sql, this would be an easy inner join. In this case, I
> >> > get
> >> > both complete tables in memory, and can only show the subset tables as
> >> > DataViews (or something like a DataView). I can't toss the original
> >> > tables
> >> > as
> >> > the user can request different views.
> >> >
> >> > Any thoughts on creating a DataView in an inner join sort of way?
> >> >
> >> > Thanks,
> >> > --
> >> > Randy
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      21st Jun 2006
Hi Randy,

It seems that you need to get the Customer information from the parent
table when you have an order in the child table. In this case, I suggest
you try to add some expression columns to the child table(Orders) which map
to the parent table columns. Then you will see all the values in the child
table.

First you will need to create DataRelation between the two tables in the
DataSet schema. Then in the DataColumn.Expression property, you can specify
as "Parent.(RelationName).CustomerName", to make the column display the
Customer's name.

Please check the following link for more information about the Expression
property.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatadatacolumnclassexpressiontopic.asp

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted DataView, but unsorted datalist when bound to the dataview CodeMonkey Microsoft ASP .NET 1 4th Feb 2011 10:55 AM
to find the data from one dataview not in another dataview joe Microsoft ADO .NET 0 9th Jul 2008 10:39 AM
DataView - How to access the row in the datatable behind the DataView Richard Microsoft VB .NET 5 17th Jul 2005 04:57 PM
Is there an easy way to copy a DataView (or even the DataGrid showing the DataView) to the Clipboard? Kevin Brown Microsoft Dot NET 4 5th Jan 2005 09:01 PM
DataView.AddNew and DataView.Count =?Utf-8?B?c3VidA==?= Microsoft ADO .NET 5 21st Mar 2004 05:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 PM.