ShowUsYour<Blog>

Irregular expressions regularly

DataTable.Compute - the filter parameter

Following on from my original posting about using the Compute method of the DataTable to execute aggregate queries, I should add that, the 2nd argument is mandatory as per the docco here:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataTableClassComputeTopic.asp

The filter parameter is the equivalent to a WHERE clause that you can use to limit the number of records that are returned to the aggregate expression. The example I gave in my previous posting was a good example of this where I used a LIKE expression in the filter parameter to get a count of persons whose name met a given criteria:

int countOfName = (int) dt.Compute("Count(Name)", "Name Like '" + entryTextBox.Text + "*'") ;

If the filter is not required, you must pass an empty string as the argument:

eldestYear.Text = dt.Compute( "MAX(DateOfBirth)", "" ).ToString() ;
youngestYear.Text = dt.Compute( "MIN(DateOfBirth)", "" ).ToString() ;

Comments

BIG said:

Help not enough
# January 27, 2004 12:55 AM

scorpion53061 said:

Pleas post an example of sorting a datatable with the compute method.
# May 10, 2004 7:22 AM

Darren Neimke said:

I'm not really sure what you mean by "sorting with the compute method"? Can you give me an example?

In the meantime, check out the Sort method of the DataView...

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatadataviewclasssorttopic.asp?frame=true
# May 10, 2004 7:29 AM

Vasasnth T T said:

I am binding a data from xml file to dataset.
This xml Error_Id column has max value of 10
when i given this query
dsMain.Tables(0).Compute("max(Error_Id)", "")
It should return me 10. But it returning as 9. What is the problem
# June 9, 2004 12:29 AM

apollo said:

VERY important! how can we select values from datatable like using the where clause. for expml select x from y where i=j

please help

# July 8, 2007 9:41 PM

kabeer said:

is it possible to use 'distinct' with compute funtion.

i.e,  dt.Compute("distinct(itemid)","")

if yes, pls give me an example

# November 30, 2007 5:03 AM

Tuck said:

It has been my experience that the first argument of the compute method must be a single expression - i..e, something like "AVG(LEN(<ColumnName>))" will throw an exception....   Does anyone have experience referencing this method from IEnumerator?  i.e., Do you know if you can you replace <ColumnName> with a column name derived from an IEnumerator iteration?

# December 20, 2007 10:48 PM

Vishal Jain said:

dt.Compute("distinct(date)","")

this function will right or not just give me help..........

# January 28, 2008 8:13 AM

Ahmet Kaymaz said:

Dear Jain,

you should use ToTable() method of DataView instead of Compute.

DataView oDv;

DataTable oDt= oDv.ToTable("TablesName", True, New String[] {"date"})

C# SQL Server VB.NET

http://www.ahmetkaymaz.com

# February 24, 2008 4:26 PM

Gouse said:

When i am using Compute Method to Sum , Beacause the first row is null ......

So how can i get rid of this problem....

# November 11, 2008 8:33 AM

devky said:

Your link to "my original posting..." is broken. Please fix it. Thank you.

# November 4, 2009 8:30 AM

Tryamabke said:

Thanks

# February 24, 2010 2:39 AM

Wrecks said:

> When i am using Compute Method to Sum,

> Beacause the first row is null

Use the filter part of Compute (the second argument) to remove the rows that contains a DbNull in that field.

# March 25, 2010 9:37 AM

kikus said:

может у кого нить есть ещё информация по этому поводу??

# June 15, 2010 5:17 PM

ITalian LAnguage Courses said:

A mutual pal mentioned I really should appear have a have a look at your site. Glad I clicked around the link! I like how you genuinely focus and get for the bottom line but can  you run by way of that final part once again? Just a little?

--------------------------------------------

my website is  

http://dogshirt.org

Also welcome you!

# December 3, 2010 3:25 AM

comet grease shark said:

I like to have a break during the my day and browse by means of some blogs to see what others are saying. This blog appeared in my search and I couldn't help  but clicking on it. I am glad I did because it was a very enjoyable read.

--------------------------------------------

my website is <a href="zeroskateboards.org/.../skateboarding-tips-to-be-as-buff-as-ryan-sheckler-shirtless.html">shirtless skaters</a> .Also welcome you!

# December 3, 2010 11:11 AM

ipad accessories store said:

We must accept finite disappointment, but we must never lose infinite hope.

-----------------------------------

# December 19, 2010 9:23 AM

ipad reviews said:

-----------------------------------------------------------

The catchy website with all the intriguing posts. You give the awesome details that a lot of men and women do not know before. most of your contents are make me have more understanding. it truly is quite diverse. I was impressed together with your web site. By no means be bored to visit your web site once more. Have the good working day.Keep loved your blogging.

# January 7, 2011 11:19 PM

Product Reviews said:

haha … the a single who's submitting the feedback

--------------------------------------------------------------------  

I have a <a href="onlytopreviews.com/">virus protection reviews</a> Website,i love him.Mania !You are welcome to look!

# January 16, 2011 8:45 PM

sachin nikam said:

I am having this result in datatable .

Jobno wagonno container no desc     status

JB001 WG001 C0001    Steam Cap Big Y

JB001 WG001 C0001    Steam Cap Small Y

JB001 WG001 C0001    Nut Bolts        Y

JB001 WG001 C0001    Flange        Y

JB001 WG001 C0001    Manlid Gasket Y

JB001 WG001 C0001    Insulation        Y

JB001 WG001 C0001    Visible Damage Y

and I want result as,

jobno wagon no containerno Steam Cap Big Steam Cap Small Nut Bolts Flange Manlid Gasket Insulation Visible Damage

JB001 WG001 C0001 Y Y Y Y Y Y Y

# June 21, 2011 1:07 AM

reddog said:

Pienso que no sois derecho. Lo invito a discutir. Escriban en PM, hablaremos.  

http://rsfiles.servehttp.com/  

jody

# August 25, 2011 5:43 PM

cheap seo services said:

qQDHOZ Really appreciate you sharing this blog article.Thanks Again. Really Great.

# October 25, 2012 7:31 PM

Milam said:

Glad to be one of several visitants on this amazing web

site : D.

# December 21, 2012 5:20 PM

Corwin said:

There several interesting points on time on this page conversely I don’t discover if these

center to heart. You'll be able to find some validity then again I most certainly will take hold opinion until I look into it further. Great article , thanks so we want more! Included with FeedBurner too

# January 27, 2013 3:05 PM

Stamps said:

Undeniably believe that which you said. Your favorite reason appeared to be on the

internet that the simplest thing to be aware of. I say to

you, I definitely find out annoyed while people think about worries that they just don’t know about.

You managed to hit the nail upon that the top and also defined

out the whole thing without having side-effects , people can take a signal.

Will likely be back to locate more. Thanks

# January 31, 2013 3:25 AM

pills for lose weight said:

zbIazv wow, awesome blog article.Thanks Again. Really Great.

# February 2, 2013 12:09 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)