Results 1 to 2 of 2

Thread: Form to SQL Helper Class?

  1. #1

    Thread Starter
    Junior Member jamison's Avatar
    Join Date
    Jan 2005
    Posts
    26

    Form to SQL Helper Class?

    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

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Form to SQL Helper Class?

    I'm not sure I understand what you mean. Why are you handling the request like this?
    Last edited by Magiaus; Feb 2nd, 2005 at 12:05 AM.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width