Insert with FormView using Linq
February 5, 2009 by: B.HardingI had a wierd error trying to insert data using a formview today.
The jist is this: the formview was trying to use an empty string for an int field instead of Nothing.
Here is the error I saw, helpful huh?
Failed to set one or more properties on type xxxxxxx Ensure that the input values are valid and can be converted to the corresponding property types.
The fields are allowed to be null but the formview just isn’t smart enough to use nothing instead of “”.
My workaround was simple and flexible enough to be re-used so I figured I would post it here.
I simply hijack the formview’s onInserting and replaced “” with Nothing for each field.
Protected Sub formView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs)
For Each o As DictionaryEntry In e.Values
If o.Value = “” Then e.Values(o.Key) = Nothing
Next
End Sub



The article is ver good. Write please more
Hello, can you please post some more information on this topic? I would like to read more.
Hi. I like the way you write. Will you post some more articles?
Nice post..Keep them coming
Thanks for sharing.
Excellent post..Keep them coming
Thanks for sharing.
ohhh great information