FormView, empty TextBox gives error: Input string was not in a cor

G

Guest

I have a few numeric fields, and when I update i get the error: "Input string
was not in a correct format". Next line:" System.Number.StringToNumber(String
str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info,
Boolean parseDecimal) +2178925"

This is beacuse some of my TextBoxes are empty (no value). If I enter a
value it is OK.

I need to use Null values to indicate that the field is not fileld in.

I've tried the property ConvertEmptyStringToNull for UpdateParameter, no
success.

How do I enter null values in FormView ?
 
G

Guest

Not quite sure what kind of update you are performing, but if you want to
update a database and want to pass a null value, then in vb.net you can use
the keyword "Nothing" (without quotes).

Regards,

KS
 
G

Guest

I guess I did not explain my problem well enough :)

As you know FormView has two-way binding. I use the FormView to view and
edit data in a table. The table contains records with numeric fields that are
null. They render OK, but if I want to update the record I can not have any
empty TextBoxes, because the "automagic" update will fail. I do not write the
update code myself, it is done by the FormView. As you see from the error
message it is conversion from tring to number that fails. this is done
"behind the scenes". If I had handled the update mself I could test for the
problem of course, but FormViw is supposed to do this for you (2 way binding).

Best regards Ottar
 
G

Guest

Ottar said:
I guess I did not explain my problem well enough :)

As you know FormView has two-way binding. I use the FormView to view and
edit data in a table. The table contains records with numeric fields that are
null. They render OK, but if I want to update the record I can not have any
empty TextBoxes, because the "automagic" update will fail. I do not write the
update code myself, it is done by the FormView. As you see from the error
message it is conversion from tring to number that fails. this is done
"behind the scenes". If I had handled the update mself I could test for the
problem of course, but FormViw is supposed to do this for you (2 way binding).

Best regards Ottar
 
G

Guest

I've been searching for two days and have not found a solution either.
Someone please answer this question...
 
G

Guest

Mark,

I did find some information that there was a bug in the clr that causes a
System.FormatException, something to do with converting ToNumber, in any case
the workaround that we are using is to on the Item_Updating event to find the
Values that need to support it to assign them to nothing when they are null.

For example, you can past this little snippet where every this can be an
issue, it assumes you are using a SQLDatasource, just change declaration and
you should be all set. We wrote this as a workaround and are hoping the MS
finds and resolves this issue as we think the ConvertEmptyStringToNull
property was put in there specifically for this issue. So we will just
remove it if it is fixed. It tries to make sure that we only override the
proper value, so if it was an output parameter and a different data type it
wouldn't be effected. You can of course just hard code the
e.NewValue(col).ToString = nothing also.

Good luck,

Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles
FormView1.ItemUpdating

Dim Formview As FormView
Dim SQLData As SqlDataSource
Dim upd As Parameter

Formview = CType(sender, FormView)
SQLData = CType(Me.FindControl(Formview.DataSourceID), SqlDataSource)

' Loop through SqlDataSource UpdateParameters and look for columns
that have null issue
' Use the ConvertEmptyStringToNull property to determine if column
should require this fix
' coupled with data type
For Each upd In SQLData.UpdateParameters
' If UpdateParameter is an empty string then determine if a
correction should be done

If e.NewValues(upd.Name).ToString = String.Empty Then

Select Case upd.Type
Case TypeCode.Decimal, TypeCode.Double, TypeCode.Single
If upd.ConvertEmptyStringToNull = True And
(upd.Direction = Data.ParameterDirection.Input Or upd.Direction =
Data.ParameterDirection.InputOutput) Then
e.NewValues(upd.Name) = Nothing
End If
End Select
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top