Greg Robinson's Blog

I report it, you decide

Click Once

Custom Authentication in Windows Forms

DataBinding Stuff

Favorite Links

My book contribution

My Book Reviews

My Personal Life

Richmond, VA .NET Users Group

Smart Client Stuff

What I am reading

March 2003 - Posts

Driving and SmartTags...grrrrr

This blog entry got me thinking

http://dotnetweblogs.com/RMcLaws/posts/4316.aspx

In Richmond, VA, we have SmartTags, or at least you can get one.  It's a little gizmo that sits in front of your rearview mirror that gets zapped as you go through a toll...no stopping, very nice, saves a ton of time.  When I drive the Vett, I just hold it up to the window as I go through the toll.

They converted 2 of the 8-10 open toll lanes on my drive to the office to Smart Tag only.  So, these 2 lines move fast while the others, Exact Change and Full Service take 5-10 minutes. 

So, what are folks doing now?  Cheap bastards will not buy a SmartTag.....no, too easy.  They will jump in the Smart Tag lanes, get right up to the toll and then flip their signal on to get over to a Exact Change and Full Service lane.  Why?  because someone always lets them over and it saves them the time of sitting in line.  Well, you have just defeated the purpose of a SmartTag only lane. Now I with my SmartTag have to sit and wait for someone to let these jerks over...grrrrrr!

And, the other day this lady simply stops, right in the middle of all 10 lanes, to start searching for coins!  Oh my god...I think 50 vehicles almost hit her!

Ok, I am done.

 

CommandBuilder...why and why not

I spent last week developing our data management layer.  Most of my testing was done with the CommandBuilder.  Although it is a handy type, I found some limitations, so I developed our own custom model.  I wish Bill's article would have come out a week sooner:

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

Nifty loop for databinding all controls on a form

I found myself databinding each control on my form one by one.  To much time, too much work.  Instead, I did this:

Dim ctrl As Control

For Each ctrl In Controls

    If TypeOf ctrl Is TextBox Then

        Dim txtName As String = ctrl.Name.ToString

        txtName = LCase(txtName.Remove(0, 3))

        ctrl.DataBindings.Add("Text", tblNames, txtName)

    ElseIf TypeOf ctrl Is ListBox Then

        ' bind to listbox here

End If

The trick here is to name your controls the same name as the datacolumn.  In the above, I name them "txt"columnname and then strip off the "txt" and make sure it's lowercase as we use lowercase for all of our columnnames.

 

 

System.Collections.Specialized.StringCollection

I needed a type that could handle an array of strings who's size I never knew.  The StringCollection type handles this very well and has some handy methods for looking into the collection.

For example, in my case I am looping through all of the datacolumns in a datarow.  As I discover a modifed column, I add the ColumnName to the StringCollection.  Later, I look inside the StringCollection to see if I have already built a SqlParameter type for the modified column.  I do this when building the primary key columns.  If the primary key was modified, I do not want to build another SqlParameter as it was already build in the first loop.

I look into the StringCollection like this:

If Not ColumnsModifed.Contains(col.ColumnName.ToString) Then

where ColumnsModified is my StringCollection and col.ColumnName.ToString is my primary key column.  I was going to use an ArrayList, however this type is not Strongly Typed and requires boxing and unboxing. .

   

Smart Client apps and security

 

As we all already know, security in .net is a beast in and of itself.  Building a Smart Client app requires the developer to really understand what is going on with security.  This article does a pretty good job, from  a high level, outlining secuirty with a Smart Client application.

Using a Dataset for datasource updates

It took me a while to figure this one out, but I got it.  I now have a piece of code that allows me to databind a dataset to controls on a client.  The client can then modify the dataset and the changes are persisted back to the datasource without using any config files or external files to describe the stored procedure being used (required paramters, param types, values, etc.). 

I am using stored procs for my updates.  The learning curve for me was figuring out how to build my sqlparameter types for the sproc calls.  I had to figure out how to:

1- grab only those DataColumns that were modified by the client and build a sqlparamter for each

2- determine the primary keys and build those sqlparameters

I grab the primary keys by setting

MissingSchemaAction = MissingSchemaAction.AddWithKey

on the data adapter fill call.  This returns an array of primary key datacolumns.  I store the array in a Property call 'PrimaryKeys'. Then, I add code to the dataadapter's OnRowUpfdating event to build my sqlparamter types.  I check to see if this is an update.  I then loop through the columns in the row to find the ones that have been modified.  I build a sqlparamter for each.  I then loop through my PrimaryKeys arrary and set each primary key.  Wala, that is it! 

Now, at runtime I know the dataSet Table primary keys, I know the modifed DataColumns and I can call dataadapter.update using a stored procedure for the update. 

Private Shared Property PrimaryKeys() As DataColumn()
        Get
            Return _primaryKeys
        End Get
        Set(ByVal Value As DataColumn())
            _primaryKeys = Value
        End Set
End Property

Protected Shared Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs)

    If e.StatementType = StatementType.Update Then

        Dim drw As DataRow = e.Row
        Dim col As DataColumn

        ' build a sqlparamter for each modifed column     

           For Each col In drw.Table.Columns
                If col.ColumnName <> "timestamp_column" Then
                    If drw(col, DataRowVersion.Current) <> drw(col, DataRowVersion.Original) Then
                        Dim myParam As New SqlParameter("@" & col.ColumnName, drw.Item(col).ToString)
                        e.Command.Parameters.Add(myParam)
                    End If
                End If
            Next

        ' build a sqlparameter for each primary key column

            For Each col In PrimaryKeys
                Dim myParam As New SqlParameter("@" & col.ColumnName, drw.Item(col).ToString)
                e.Command.Parameters.Add(myParam)
            Next

        End If

    End Sub

    

 

 

The Smart Family

I know we are suppose to keep our blogs related to .net, however this is truly unbelievable:

http://www.cnn.com/2003/US/West/03/12/smart.family.reax/

We do not have kids, 4 dogs and a cat, not close, but they are our kids. I cannot even begin to imagine how this family feels.  You lose your child, 9 months go by, and she reappers.  Can one even begin to understand the emotional roller coaster this family has been on.  Wow!

Kinda like the movie Cast Away.  I mean, you almost have to assume at some point you have lost this person.  How does one do that and then somehow this person is discovered, alive.  Man, just trying to play this out in my mind turns my stomach.

 

 

 

 

 

 

The DataGrid Girls?

OK, I have now seen it all

http://www.datagridgirl.com/default.aspx

Call me textbox boy!

MSDN on TV

This looks good:

http://msdn.microsoft.com/msdntv/default.aspx

 

Looking for a .net developer

I am looking for a .net developer to assist me on the application I am currently re-writing.  I am looking for someone who is as passionate about .net as I am and who is not simply looking for a paycheck, 9-5 position. 

This could be part-time, full-time, contract, employee.  It really depends on the candidate.  Our company is small so you must be self-motivated and be able to work well on your own.  The position is in Richmond VA.  Remote, off-site is a possibility. however you will need to be in Richmond the majority of the time. 

If your first question is "What language", do not bother replying.

E-mail me if interested or if you know of someone who may be.    

More Posts Next page »