Wednesday, November 18, 2009

Distinct in datatable

This is how to do a distinct in a datatable in Visual Basic. It is derived from http://support.microsoft.com/default.aspx?scid=kb;en-us;326176#1 and also look at this definition http://weblogs.asp.net/eporter/archive/2005/02/10/370548.aspx for multiple columns / fields.

Private

Function ColumnEqual(ByRef A As Object, ByRef B As Object) As Boolean

' Compares two values to see if they are equal. Also compares DBNULL.Value.
' Note: If your DataTable contains object fields, then you must extend this
' function to handle them in a meaningful way if you intend to group on them.

If IsDBNull(A) And IsDBNull(B) Then

Return True

End If

If IsDBNull(A) Or IsDBNull(B) Then

Return False

End If

If A = B Then

Return True

End If

End Function

Public Function SelectDistinct(ByVal TableName As String, ByRef SourceTable As DataTable, ByVal FieldName As String) As DataTable

Dim dt As New DataTable(TableName)

Dim dr As DataRow

dt.Columns.Add(FieldName, SourceTable.Columns(FieldName).DataType)

Dim LastValue As Object = DBNull.Value

For Each dr In SourceTable.Select("", FieldName)

If IsDBNull(LastValue) Or Not ColumnEqual(LastValue, dr(FieldName)) Then

LastValue = dr(FieldName)

dt.Rows.Add(LastValue)

End If

Next

Return dt

End Function

Monday, November 16, 2009

What really ticks me off..

is that I like some of the things on Al-Gore TV, otherwise known as current_tv. God help me.

http://current.com/sarah-haskins/

Actually, this is the only person that I follow...and she isn't for kids. Dang it, why do the political gods do this to me?

Friday, November 6, 2009

Tyranny Again

Pelosi Breaks Pledge to Put Final Health Care Bill Online for 72 Hours Before Vote

http://www.weeklystandard.com/weblogs/TWSFP/2009/11/pelosi_breaks_pledge_to_put_he.asp

Evidently, it is too much to submit the bill to the stupid american public before the house votes to end freedom as we know it. The health plan will put our LIVES into the hands of faceless bureaucrats that take our money at the threat of imprisonment and will eventually bankrupt our country. I though Social Security would eventually do that, but it seems that we are bound to destroy our country a lot faster than that.

I have gone from loving my country and principles to hating what we have done with it.