Datareader using column names. Surely there's a better way
-
Hey I'm retrieving datat using a datareader as follows
If Not IsDBNull(dr("ClientID")) Then ClientLink.HRef = Page.ResolveUrl("~/secure_code/clients/ViewClient.aspx") + "?ClientID=" + dr.GetInt32(1).ToString() End If
But i would prefer to use the column name instead of it's index as I use the SP in various places and would like the flexibility to alter it how ever I feel I want to without anything breaking. ISDBnull allows you to just type in the column name as a string but all of the get methods don't. All I could work out was this.If Not IsDBNull(dr("ClientID")) Then ClientLink.HRef = Page.ResolveUrl("~/secure_code/clients/ViewClient.aspx") + "?ClientID=" + dr.GetInt32(dr.GetOrdinal("ClientID")).ToString() End If
Is there a better way???