|
|
|
start date: Fri, 17 Aug 2007 16:04:18 -0700,
posted on: microsoft.public.dotnet.framework.adonet
back
| Thread Index |
|
1
SpaceMarine
|
|
2
Cor Ligthert[MVP]
|
|
3
Cor Ligthert[MVP]
|
|
4
Miha Markic miha at rthand com
|
|
5
Miha Markic miha at rthand com
|
|
6
SpaceMarine
|
|
7
SpaceMarine
|
|
8
Amit
|
|
9
Amit
|
|
10
Miha Markic miha at rthand com
|
|
11
Miha Markic miha at rthand com
|
DataTable.Compute() question
hello,
i have a big datable of a bunch of stuff. i am interested in getting
row counts that match certain criteria.
currently i do this by creating a new DataView for each criteria, and
getting its .RowCount. like so:
dv = New DataView(dt, "Type = 2", "Type",
DataViewRowState.CurrentRows)
total = dv.Count
writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
....that works, but i was wondering -- is there a way to use the
DataTable.Compute() method to do this? i had tried something like
this, but it didnt work:
Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
....this doesnt work because the aggregate function Count() isnt
designed to work this way. but is there something that is?
thanks!
matt
Date:Fri, 17 Aug 2007 16:04:18 -0700
Author:
|
Re: DataTable.Compute() question
Matt,
Maybe there is, however what you think to win with that, in my idea is your
method very inventive and most probably the fastest you can get.
Cor
"SpaceMarine" schreef in bericht
news:1187391858.515468.75440@19g2000hsx.googlegroups.com...
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
>
Date:Sat, 18 Aug 2007 07:24:40 +0200
Author:
|
Re: DataTable.Compute() question
Matt,
Maybe there is, however what you think to win with that, in my idea is your
method very inventive and most probably the fastest you can get.
Cor
"SpaceMarine" schreef in bericht
news:1187391858.515468.75440@19g2000hsx.googlegroups.com...
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
>
Date:Sat, 18 Aug 2007 07:24:40 +0200
Author:
|
Re: DataTable.Compute() question
No, you can't use Compute for this one.
As an alternative (similar to your solution) you might use DataTable.Select
method.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"SpaceMarine" wrote in message
news:1187391858.515468.75440@19g2000hsx.googlegroups.com...
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
>
Date:Mon, 20 Aug 2007 10:46:16 +0200
Author:
|
Re: DataTable.Compute() question
No, you can't use Compute for this one.
As an alternative (similar to your solution) you might use DataTable.Select
method.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"SpaceMarine" wrote in message
news:1187391858.515468.75440@19g2000hsx.googlegroups.com...
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
>
Date:Mon, 20 Aug 2007 10:46:16 +0200
Author:
|
Re: DataTable.Compute() question
On Aug 20, 3:46 am, "Miha Markic" <miha at rthand com> wrote:
> No, you can't use Compute for this one.
> As an alternative (similar to your solution) you might use DataTable.Select
> method.
i see. thanks all.
sm
Date:Mon, 20 Aug 2007 09:28:20 -0700
Author:
|
Re: DataTable.Compute() question
On Aug 20, 3:46 am, "Miha Markic" <miha at rthand com> wrote:
> No, you can't use Compute for this one.
> As an alternative (similar to your solution) you might use DataTable.Select
> method.
i see. thanks all.
sm
Date:Mon, 20 Aug 2007 09:28:20 -0700
Author:
|
Re: DataTable.Compute() question
On Aug 17, 4:04 pm, SpaceMarine wrote:
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
Can't you use dt.Rows.Length
And I don't think DataTable.Select provides too much options either
Date:Wed, 22 Aug 2007 04:15:59 -0000
Author:
|
Re: DataTable.Compute() question
On Aug 17, 4:04 pm, SpaceMarine wrote:
> hello,
>
> i have a big datable of a bunch of stuff. i am interested in getting
> row counts that match certain criteria.
>
> currently i do this by creating a new DataView for each criteria, and
> getting its .RowCount. like so:
>
> dv = New DataView(dt, "Type = 2", "Type",
> DataViewRowState.CurrentRows)
> total = dv.Count
> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>
> ...that works, but i was wondering -- is there a way to use the
> DataTable.Compute() method to do this? i had tried something like
> this, but it didnt work:
>
> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>
> ...this doesnt work because the aggregate function Count() isnt
> designed to work this way. but is there something that is?
>
> thanks!
> matt
Can't you use dt.Rows.Length
And I don't think DataTable.Select provides too much options either
Date:Wed, 22 Aug 2007 04:15:59 -0000
Author:
|
Re: DataTable.Compute() question
"Amit" wrote in message
news:1187756159.591150.158790@l22g2000prc.googlegroups.com...
> On Aug 17, 4:04 pm, SpaceMarine wrote:
>> hello,
>>
>> i have a big datable of a bunch of stuff. i am interested in getting
>> row counts that match certain criteria.
>>
>> currently i do this by creating a new DataView for each criteria, and
>> getting its .RowCount. like so:
>>
>> dv = New DataView(dt, "Type = 2", "Type",
>> DataViewRowState.CurrentRows)
>> total = dv.Count
>> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>>
>> ...that works, but i was wondering -- is there a way to use the
>> DataTable.Compute() method to do this? i had tried something like
>> this, but it didnt work:
>>
>> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>>
>> ...this doesnt work because the aggregate function Count() isnt
>> designed to work this way. but is there something that is?
>>
>> thanks!
>> matt
>
> Can't you use dt.Rows.Length
No. He needs to count *filtered* rows, not all rows.
> And I don't think DataTable.Select provides too much options either
No, it doesn't - it is quite same as creating a DataView, it is just less
code in this scenario.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
Date:Wed, 22 Aug 2007 09:41:03 +0200
Author:
|
Re: DataTable.Compute() question
"Amit" wrote in message
news:1187756159.591150.158790@l22g2000prc.googlegroups.com...
> On Aug 17, 4:04 pm, SpaceMarine wrote:
>> hello,
>>
>> i have a big datable of a bunch of stuff. i am interested in getting
>> row counts that match certain criteria.
>>
>> currently i do this by creating a new DataView for each criteria, and
>> getting its .RowCount. like so:
>>
>> dv = New DataView(dt, "Type = 2", "Type",
>> DataViewRowState.CurrentRows)
>> total = dv.Count
>> writer.WriteLine(String.Format("Lines of Type 2: {0}.", total))
>>
>> ...that works, but i was wondering -- is there a way to use the
>> DataTable.Compute() method to do this? i had tried something like
>> this, but it didnt work:
>>
>> Dim oTotal As Object = dt.Compute("Count(*)", "Type = 2")
>>
>> ...this doesnt work because the aggregate function Count() isnt
>> designed to work this way. but is there something that is?
>>
>> thanks!
>> matt
>
> Can't you use dt.Rows.Length
No. He needs to count *filtered* rows, not all rows.
> And I don't think DataTable.Select provides too much options either
No, it doesn't - it is quite same as creating a DataView, it is just less
code in this scenario.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
Date:Wed, 22 Aug 2007 09:41:03 +0200
Author:
|
|
|