PC Review


Reply
Thread Tools Rate Thread

Aggregate column uses defaultview?

 
 
benji
Guest
Posts: n/a
 
      18th Dec 2007
Hi,

I have two tables related to eachother, and one table has an
expression-based column that states "SUM(Child.Price)". Am I able to adjust
the child table's default view, and expect that the result of the SUM will be
affected? Is there any extra action I need to take to trigger a "refresh"
after adjusting the default view?

Thanks...

-Ben
 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      19th Dec 2007
Benji,

It depends how you refresh your tables, as you create everytime new
datatables (or datasets), then you have to refresh (set) the datasource as
well. The datasource is set to a reference so with a new dataset
(datatable), that needs as well to set to that.

I am not sure if this answers your question, however in my idea is your
question a little bit of a puzzle because it can be about thousands of
different problems with a factor of solutions to that.

Cor

"benji" <(E-Mail Removed)> schreef in bericht
news:22C05DF8-BA4F-421A-9C4D-(E-Mail Removed)...
> Hi,
>
> I have two tables related to eachother, and one table has an
> expression-based column that states "SUM(Child.Price)". Am I able to
> adjust
> the child table's default view, and expect that the result of the SUM will
> be
> affected? Is there any extra action I need to take to trigger a "refresh"
> after adjusting the default view?
>
> Thanks...
>
> -Ben


 
Reply With Quote
 
benji
Guest
Posts: n/a
 
      19th Dec 2007
Hi Cor,

Thanks for your response. I think a code sample might be helpful. Take a
look at the following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim mydatset As New Data.DataSet

Dim mytable1 As New Data.DataTable("Parent")
Dim mytable2 As New Data.DataTable("Child")
mydatset.Tables.Add(mytable1)
mydatset.Tables.Add(mytable2)

Dim mycol As New Data.DataColumn("Product", GetType(String))
Dim mycolchild As New Data.DataColumn("Product", GetType(String))
mytable1.Columns.Add(mycol)
mytable2.Columns.Add(mycolchild)
mytable2.Columns.Add("Price", GetType(Double))
mytable2.Columns.Add("PurchaseDate", GetType(DateTime))


Dim myrow = mytable2.NewRow()
Dim rowVals(2) As Object
rowVals(0) = "Telephone"
rowVals(1) = 50.5
rowVals(2) = DateTime.Parse("7/7/2007")


mytable2.Rows.Add(rowVals)

rowVals(0) = "Telephone"
rowVals(1) = 50.5
rowVals(2) = DateTime.Parse("7/7/2006")

mytable2.Rows.Add(rowVals)
mytable2.DefaultView.RowFilter = "PurchaseDate>#8/8/2006#"

mydatset.Relations.Add("MyRelation",
mydatset.Tables("Parent").Columns("Product"),
mydatset.Tables("Child").Columns("Product"), False)

mytable1.Columns.Add("MyExprCol", GetType(Double), "SUM(Child.Price)")


Dim newrowVals(0) As Object
newrowVals(0) = "Telephone"
mytable1.Rows.Add(newrowVals)


MyGrid.DataSource = mytable1
MyGrid.DataBind()

End Sub

The datagrid shows

Product MyExprCol
Telephone 101

Therefore it is ignoring the default filter. If it were minding the filter,
it would ignore the 7/7/2006 entry and show a sum of 50.5, rather than 101.
I've tried setting the filter in different spots in code. Is this expected?
How can I use a subset of the data for the aggregation?

Thanks...

-Ben


"Cor Ligthert[MVP]" wrote:

> Benji,
>
> It depends how you refresh your tables, as you create everytime new
> datatables (or datasets), then you have to refresh (set) the datasource as
> well. The datasource is set to a reference so with a new dataset
> (datatable), that needs as well to set to that.
>
> I am not sure if this answers your question, however in my idea is your
> question a little bit of a puzzle because it can be about thousands of
> different problems with a factor of solutions to that.
>
> Cor
>
> "benji" <(E-Mail Removed)> schreef in bericht
> news:22C05DF8-BA4F-421A-9C4D-(E-Mail Removed)...
> > Hi,
> >
> > I have two tables related to eachother, and one table has an
> > expression-based column that states "SUM(Child.Price)". Am I able to
> > adjust
> > the child table's default view, and expect that the result of the SUM will
> > be
> > affected? Is there any extra action I need to take to trigger a "refresh"
> > after adjusting the default view?
> >
> > Thanks...
> >
> > -Ben

>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      19th Dec 2007
Benji,

I don't think the expression is that strong that it takes the defaultview.

This was what came into my mind (it is tested with your code and gave 50,5)

\\\
Dim mytable3 As DataTable = mytable2.DefaultView.ToTable
mytable3.TableName = "FilteredChild"
mydatset.Tables.Add(mytable3)

mydatset.Relations.Add("MyRelation",
mydatset.Tables("Parent").Columns("Product"),
mydatset.Tables("FilteredChild").Columns("Product"), False)
///

By the way; Nicely done those culture independent dates and a very good way
to show the problem.

Cor



"benji" <(E-Mail Removed)> schreef in bericht
news:9EDA0A8E-49C5-4501-9238-(E-Mail Removed)...
> Hi Cor,
>
> Thanks for your response. I think a code sample might be helpful. Take a
> look at the following:
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Handles Me.Load
> Dim mydatset As New Data.DataSet
>
> Dim mytable1 As New Data.DataTable("Parent")
> Dim mytable2 As New Data.DataTable("Child")
> mydatset.Tables.Add(mytable1)
> mydatset.Tables.Add(mytable2)
>
> Dim mycol As New Data.DataColumn("Product", GetType(String))
> Dim mycolchild As New Data.DataColumn("Product", GetType(String))
> mytable1.Columns.Add(mycol)
> mytable2.Columns.Add(mycolchild)
> mytable2.Columns.Add("Price", GetType(Double))
> mytable2.Columns.Add("PurchaseDate", GetType(DateTime))
>
>
> Dim myrow = mytable2.NewRow()
> Dim rowVals(2) As Object
> rowVals(0) = "Telephone"
> rowVals(1) = 50.5
> rowVals(2) = DateTime.Parse("7/7/2007")
>
>
> mytable2.Rows.Add(rowVals)
>
> rowVals(0) = "Telephone"
> rowVals(1) = 50.5
> rowVals(2) = DateTime.Parse("7/7/2006")
>
> mytable2.Rows.Add(rowVals)
> mytable2.DefaultView.RowFilter = "PurchaseDate>#8/8/2006#"
>
> mydatset.Relations.Add("MyRelation",
> mydatset.Tables("Parent").Columns("Product"),
> mydatset.Tables("Child").Columns("Product"), False)
>
> mytable1.Columns.Add("MyExprCol", GetType(Double),
> "SUM(Child.Price)")
>
>
> Dim newrowVals(0) As Object
> newrowVals(0) = "Telephone"
> mytable1.Rows.Add(newrowVals)
>
>
> MyGrid.DataSource = mytable1
> MyGrid.DataBind()
>
> End Sub
>
> The datagrid shows
>
> Product MyExprCol
> Telephone 101
>
> Therefore it is ignoring the default filter. If it were minding the
> filter,
> it would ignore the 7/7/2006 entry and show a sum of 50.5, rather than
> 101.
> I've tried setting the filter in different spots in code. Is this
> expected?
> How can I use a subset of the data for the aggregation?
>
> Thanks...
>
> -Ben
>
>
> "Cor Ligthert[MVP]" wrote:
>
>> Benji,
>>
>> It depends how you refresh your tables, as you create everytime new
>> datatables (or datasets), then you have to refresh (set) the datasource
>> as
>> well. The datasource is set to a reference so with a new dataset
>> (datatable), that needs as well to set to that.
>>
>> I am not sure if this answers your question, however in my idea is your
>> question a little bit of a puzzle because it can be about thousands of
>> different problems with a factor of solutions to that.
>>
>> Cor
>>
>> "benji" <(E-Mail Removed)> schreef in bericht
>> news:22C05DF8-BA4F-421A-9C4D-(E-Mail Removed)...
>> > Hi,
>> >
>> > I have two tables related to eachother, and one table has an
>> > expression-based column that states "SUM(Child.Price)". Am I able to
>> > adjust
>> > the child table's default view, and expect that the result of the SUM
>> > will
>> > be
>> > affected? Is there any extra action I need to take to trigger a
>> > "refresh"
>> > after adjusting the default view?
>> >
>> > Thanks...
>> >
>> > -Ben

>>


 
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
Need help with DefaultView.RowFilter gottfried.lesigang@web.de Microsoft ADO .NET 2 3rd Mar 2009 08:22 PM
Aggregate Data from a column in a cell =?Utf-8?B?RW5yb24=?= Microsoft Excel Worksheet Functions 0 20th Feb 2006 04:36 PM
DefaultView Anne Microsoft Access Form Coding 4 3rd Jul 2004 05:12 AM
Re: Change DefaultView using VBA George Nicholson Microsoft Access Form Coding 2 3rd Jun 2004 04:59 PM
Can't use aggregate in Expression column from designer =?Utf-8?B?Sm9obiBDbGVtZW50?= Microsoft ADO .NET 0 26th Feb 2004 04:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:55 AM.