Daily Archives: June 7, 2004

ADO.NET 2.0: DataView.ToTable DISTINCT!! Hooray Hooray!

Because I had to write a DistinctRows function last night, today I looked at the May bits of VS2005 to see if they had addressed this really obvious need, and indeed they did! Hooray hoorah!

OverLoads Public Function ToTable( _ ByVal distinct As Boolean, _ ByVal columnNames() As String _) As DataTable

Here’s the quick hack I wrote last night if you want to use it. It sorts the table on the keyfield then walks through it grabbing every row where the value of the key field changes and stuffing it into a new datatable that is returned. No rocket science. Just another one of those things I wonder why I had to write the code.

(note – the int32_key is in there as a reminder in case I need to create another one for non-int keys)

Public Function DistinctRows_Int32_Key(ByVal dt As DataTable, ByVal keyfield As String) As DataTable
  
Dim newTable As DataTable = dt.Clone
  
Dim keyval As Int32 = 0
  
Dim dv As DataView = dt.DefaultView
  
dv.Sort = keyfield
  
If dt.Rows.Count > 0 Then
    
For Each dr As DataRow In dt.Rows
     
If Not dr.Item(keyfield) = keyval Then
       
newTable.ImportRow(dr)
       
keyval = dr.Item(keyfield)
     
End If
   
Next
 
Else
   
newTable = dt.Clone
 
End If
 
Return newTable
End Function

Caricatures at Sea World

At Sea World, there were 3 caricature artists lined up doing drawings of people. Each artist had a very different style. For example, Steele Price got the “Hollywood movie star” artist. I sat for a pic with Renee Rieser and we got the artist that every politician fears – well, thank goodness we don’t have big ears. We got the “exaggerate everything” artist. I have never been unaware that I have a large nose… but those teeth and that little dangling chin! LOL! Well, I guess I smile a lot. Anyway, Renee and I are reversed when standing with the pic (and the artist who is holding it). The drawing on the left is Renee and the one on the right is [supposedly] me 🙂