HighTechTalks DotNet Forums  

Aggregate column uses defaultview?

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Aggregate column uses defaultview? in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
benji
 
Posts: n/a

Default Aggregate column uses defaultview? - 12-18-2007 , 01:55 PM






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
  #2  
Old   
Cor Ligthert[MVP]
 
Posts: n/a

Default Re: Aggregate column uses defaultview? - 12-18-2007 , 10:29 PM






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" <benji (AT) discussions (DOT) microsoft.com> schreef in bericht
news:22C05DF8-BA4F-421A-9C4D-BC0C5287570E (AT) microsoft (DOT) com...
Quote:
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
  #3  
Old   
benji
 
Posts: n/a

Default Re: Aggregate column uses defaultview? - 12-19-2007 , 10:05 AM



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:

Quote:
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" <benji (AT) discussions (DOT) microsoft.com> schreef in bericht
news:22C05DF8-BA4F-421A-9C4D-BC0C5287570E (AT) microsoft (DOT) com...
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
  #4  
Old   
Cor Ligthert[MVP]
 
Posts: n/a

Default Re: Aggregate column uses defaultview? - 12-19-2007 , 12:13 PM



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" <benji (AT) discussions (DOT) microsoft.com> schreef in bericht
news:9EDA0A8E-49C5-4501-9238-55BBACAD469D (AT) microsoft (DOT) com...
Quote:
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" <benji (AT) discussions (DOT) microsoft.com> schreef in bericht
news:22C05DF8-BA4F-421A-9C4D-BC0C5287570E (AT) microsoft (DOT) com...
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 Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.