Hi does anyone have a helper class for converting Request.Form values to a suitable SQL value or system value? I'm posting a a function in a seperate thread I find useful in the interest of code sharing.

Right now I have a simple information class and I am using reflection to get all it's properties. Then I am looping thru the form keys, and setting any matches. I am getting an error because drop downs are listed in the form keys array even if no value was selected. So I want some kind of function that accepts (object, system.type) and makes sure the object value in an acceptable value for the given type. i.e. "" goes to "0" for an integer, "on" goes to "true" for a checkbox boolean.

VB Code:
  1. Public Sub LoadInfoFromRequest(ByRef myInfo As MyInfoBase)
  2.  
  3.  
  4.         Dim f As System.Reflection.FieldInfo
  5.         Dim x As Integer
  6.         Dim o As Object
  7.         Dim n, t As String
  8.         Dim FormKeys() As String
  9.  
  10.         'Use reflection to get the fields
  11.         Dim myFieldInfo() As System.Reflection.FieldInfo
  12.         myFieldInfo = myInfo.GetType().GetFields()
  13.  
  14.         'Load the object from the datarow.
  15.         FormKeys = HttpContext.Current.Request.Form.AllKeys
  16.         For Each f In myFieldInfo
  17.             x = FormKeys.IndexOf(FormKeys, f.Name)
  18.             If x >= 0 Then
  19.                 n = f.Name
  20.                 t = f.GetType().ToString
  21.                 o = HttpContext.Current.Request.Form(f.Name)
  22.                 'I need some function here like ConvertObjectValue( object, system.type)
  23.                 f.SetValue(myInfo, o)
  24.             End If
  25.         Next
  26.  
  27.     End Sub

Thanks,
Jamie