By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 ?
Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

"Ottar" wrote:
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 ?

Nov 19 '05 #2

P: n/a
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

"saleek" wrote:
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

"Ottar" wrote:
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 ?

Nov 19 '05 #3

P: n/a


"Ottar" wrote:
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

"saleek" wrote:
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

"Ottar" wrote:
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 ?

Nov 19 '05 #4

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

"Ottar" wrote:
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

"saleek" wrote:
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

"Ottar" wrote:
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 ?

Nov 19 '05 #5

P: n/a


"Ottar" wrote:
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

"saleek" wrote:
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

"Ottar" wrote:
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 ?

Nov 19 '05 #6

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

"Ottar" wrote:
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

"saleek" wrote:
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

"Ottar" wrote:
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 ?

Nov 19 '05 #7

P: n/a
Did you solve this as I am having the same problem?

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

"Ottar" wrote:
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

"saleek" wrote:
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

"Ottar" wrote:

> 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 ?

Nov 19 '05 #8

P: n/a
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

"Mark McDonald" wrote:
Did you solve this as I am having the same problem?

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

"Ottar" wrote:
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

"saleek" wrote:

> 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
>
> "Ottar" wrote:
>
> > 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 ?

Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.