ericgehrman.com

tech

Select Distinct on DataSets

by admin on Aug.04, 2010, under tech

Have you ever wondered how to do a “SELECT DISTINCT” on a dataset column? Well, here’s the low down:

I came across this handy little method for querying a DataSet for distinct records . Say that my data is already in my app and I need to do something with it. Going back to SQL or re-writing the query just isn’t an option, so what can I do?

Microsoft has a helpful kb where it defines a dataset helper class and a SelectDistinct method for accessing data in this way – here. But as always, Microsoft makes simple things complicated. And who wants to write a bunch of classes and functions when we can do the same thing in one line?

Say we have a DataSet ds like so:

ID grID value
1 100 abc
2 100 def
3 110 efg
4 120 hij

To select distinct grIDs we can just do this:

DataTable distinctDT = ds.Tables[0].DefaultView.ToTable(true, new string [] { “grID” });

This returns:

grID
100
110
120

We can now use this distinct DataTable to make our queries on our original DataSet:

ds.Tables[0].Select(“grID = ” distinctDT.Rows[0]["grID"].toString());

Yeah! No helper classes and no extra methods taking up that valuable development space. Hope this helps someone!

Leave a Comment :, more...

Iphone, yeay!

by admin on Sep.05, 2008, under tech

Finally, a year and 3 months after initial release, I got myself an Iphone (3G), thanks to my company.

I must say, this is one hell of a device. I am pretty impressed with the little gadget. The one thing, and I do mean one thing, I’m not impressed with is the initial battery life. I have a few fetch emails and one push email account setup on the phone. Other than that, I haven’t really been using the thing too much. In fact, right now, 5.5 hours after it was fully charged, I have about 1/4 or less battery left. Some people have told me that this levels out after a few weeks, which makes absolutely no logical sense – Except that maybe after a few weeks, I wont be quite as enthralled by the device; therefore using it a bit less.

Anyways, I really hope that this little nuance levels itself out a little bit. In these 29 years of life, I’ve come to find that even the best things have at the very least one thing wrong with them. Oh well….

UPDATE: I took my phone to the ‘geniuses’ at the apple store and apparently I had a bad apple (pun intended). They were quick to issue me a replacement and my battery life has increased ten fold. Hooray. Now this little bugger is great!

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...