|
-
Jan 31st, 2005, 05:57 PM
#1
Thread Starter
Junior Member
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:
Public Sub LoadInfoFromRequest(ByRef myInfo As MyInfoBase)
Dim f As System.Reflection.FieldInfo
Dim x As Integer
Dim o As Object
Dim n, t As String
Dim FormKeys() As String
'Use reflection to get the fields
Dim myFieldInfo() As System.Reflection.FieldInfo
myFieldInfo = myInfo.GetType().GetFields()
'Load the object from the datarow.
FormKeys = HttpContext.Current.Request.Form.AllKeys
For Each f In myFieldInfo
x = FormKeys.IndexOf(FormKeys, f.Name)
If x >= 0 Then
n = f.Name
t = f.GetType().ToString
o = HttpContext.Current.Request.Form(f.Name)
'I need some function here like ConvertObjectValue( object, system.type)
f.SetValue(myInfo, o)
End If
Next
End Sub
Thanks,
Jamie
-
Feb 2nd, 2005, 12:01 AM
#2
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|