HighTechTalks DotNet Forums  

{0:c} causes input string not in correct format exception

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss {0:c} causes input string not in correct format exception in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Scott M.
 
Posts: n/a

Default {0:c} causes input string not in correct format exception - 11-19-2007 , 07:43 PM






I've seen many posts complaining about this, but none with a solution.....

I have a GridView that is bound to a SQLDataSource and working just fine,
except that when I change the DataFormatString on one of my columns that is
displaying a smallmoney value from SQL (converted to double by .NET
Framework) to {0:c}, I get an Input String Was Not In Correct Format
exception when I attempt to delete a record. Interestgly, editing works
just fine.

I know that the problem is that when the delete takes place, the field
contains something like $299.95, which is clearly not a double or
Interestingly, and thus the error. The 64,000 question is how to fix this
so that when the delete takes place, the data is back in it's original
(unformatted) form. I've tried stripping the "$" and the "," out of the
value in the RowDeleting event handler to no avail.

Any ideas?


Reply With Quote
  #2  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default RE: {0:c} causes input string not in correct format exception - 11-19-2007 , 10:47 PM






Hi Scott,

From your description, you're encountering some "input string incorrect
format ..." error when deleting record in GridView(with DataFormatString
set in column), right?

According to the setting you mentioned, I've performed a simple test with
the following things:


* use a simple SQL Express table with a column(of "smallmoney" type)
* in ASPX page, you SqlDataSource to connect that table(enable edit, delete)
* in GridView, enable Edit,Delete and also apply the following formatstring
to the boundField(of that smallmoney column)

"{0:c}"


============
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" />
</Columns>
</asp:GridView>
=================

However, the currency symbol doesn't display by default and I can get the
record updated or deleted correctly. Therefore, I think there should be
something different from mine in your page. Would you give me a aspx
template so that I can test against it?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
Quote:
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: {0:c} causes input string not in correct format exception
Date: Mon, 19 Nov 2007 20:43:58 -0500

I've seen many posts complaining about this, but none with a solution.....

I have a GridView that is bound to a SQLDataSource and working just fine,
except that when I change the DataFormatString on one of my columns that
is
displaying a smallmoney value from SQL (converted to double by .NET
Framework) to {0:c}, I get an Input String Was Not In Correct Format
exception when I attempt to delete a record. Interestgly, editing works
just fine.

I know that the problem is that when the delete takes place, the field
contains something like $299.95, which is clearly not a double or
Interestingly, and thus the error. The 64,000 question is how to fix this
so that when the delete takes place, the data is back in it's original
(unformatted) form. I've tried stripping the "$" and the "," out of the
value in the RowDeleting event handler to no avail.

Any ideas?




Reply With Quote
  #3  
Old   
Scott M.
 
Posts: n/a

Default Re: {0:c} causes input string not in correct format exception - 11-19-2007 , 11:22 PM



Is this what you want Steven:

<asp:BoundField DataField="RetailPrice"
HeaderText="RetailPrice" SortExpression="RetailPrice"
DataFormatString="{0:c}" />

This does cause my displayed amounts to be formatted as currency, which is a
"catch 22" since now when I try to delete, the value in the bound field is
not the same as it was when it was loaded into the gridview. Now, the value
in this column is no longer compatible with a decimal, double or smallmoney
and so the delete attempt fails.

You mention that you are not seeing your smallmoney SQL amount formatted as
a currency amount, which you should be, so I think you don't have your test
set up correctly.

-Scott


"Steven Cheng[MSFT]" <stcheng (AT) online (DOT) microsoft.com> wrote

Quote:
Hi Scott,

From your description, you're encountering some "input string incorrect
format ..." error when deleting record in GridView(with DataFormatString
set in column), right?

According to the setting you mentioned, I've performed a simple test with
the following things:


* use a simple SQL Express table with a column(of "smallmoney" type)
* in ASPX page, you SqlDataSource to connect that table(enable edit,
delete)
* in GridView, enable Edit,Delete and also apply the following
formatstring
to the boundField(of that smallmoney column)

"{0:c}"


============
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1"
Columns
asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" /
asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" /
asp:BoundField DataField="name" HeaderText="name" SortExpression="name"
/
asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" /
/Columns
/asp:GridView
=================

However, the currency symbol doesn't display by default and I can get the
record updated or deleted correctly. Therefore, I think there should be
something different from mine in your page. Would you give me a aspx
template so that I can test against it?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



--------------------
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: {0:c} causes input string not in correct format exception
Date: Mon, 19 Nov 2007 20:43:58 -0500

I've seen many posts complaining about this, but none with a solution.....

I have a GridView that is bound to a SQLDataSource and working just fine,
except that when I change the DataFormatString on one of my columns that
is
displaying a smallmoney value from SQL (converted to double by .NET
Framework) to {0:c}, I get an Input String Was Not In Correct Format
exception when I attempt to delete a record. Interestgly, editing works
just fine.

I know that the problem is that when the delete takes place, the field
contains something like $299.95, which is clearly not a double or
Interestingly, and thus the error. The 64,000 question is how to fix this
so that when the delete takes place, the data is back in it's original
(unformatted) form. I've tried stripping the "$" and the "," out of the
value in the RowDeleting event handler to no avail.

Any ideas?





Reply With Quote
  #4  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default Re: {0:c} causes input string not in correct format exception - 11-21-2007 , 03:46 AM



Hi Scott,

Here is the aspx template of my test page

price column is the one of smallmoney type in SQL Express:

=======================
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
DeleteCommand="DELETE FROM [sm_tb] WHERE [id] = @id"
InsertCommand="INSERT INTO [sm_tb] ([name], [price]) VALUES (@name, @price)"
SelectCommand="SELECT [id], [name], [price] FROM [sm_tb]"
UpdateCommand="UPDATE [sm_tb] SET [name] = @name, [price] = @price WHERE
[id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="price" Type="Decimal" />
<asp:Parameter Name="id" Type="Int64" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="price" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" />
</Columns>
</asp:GridView>

</div>
</form>
===========================

Anything I should changed to match your case?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.










--------------------
Quote:
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: Re: {0:c} causes input string not in correct format exception
Date: Tue, 20 Nov 2007 00:22:04 -0500


Is this what you want Steven:

asp:BoundField DataField="RetailPrice"
HeaderText="RetailPrice" SortExpression="RetailPrice"
DataFormatString="{0:c}" /

This does cause my displayed amounts to be formatted as currency, which is
a
"catch 22" since now when I try to delete, the value in the bound field is
not the same as it was when it was loaded into the gridview. Now, the
value
in this column is no longer compatible with a decimal, double or
smallmoney
and so the delete attempt fails.

You mention that you are not seeing your smallmoney SQL amount formatted
as
a currency amount, which you should be, so I think you don't have your
test
set up correctly.

-Scott


"Steven Cheng[MSFT]" <stcheng (AT) online (DOT) microsoft.com> wrote in message
news:%23ZQDxBzKIHA.5204 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Hi Scott,

From your description, you're encountering some "input string incorrect
format ..." error when deleting record in GridView(with DataFormatString
set in column), right?

According to the setting you mentioned, I've performed a simple test with
the following things:


* use a simple SQL Express table with a column(of "smallmoney" type)
* in ASPX page, you SqlDataSource to connect that table(enable edit,
delete)
* in GridView, enable Edit,Delete and also apply the following
formatstring
to the boundField(of that smallmoney column)

"{0:c}"


============
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1"
Columns
asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" /
asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" /
asp:BoundField DataField="name" HeaderText="name" SortExpression="name"
/
asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" /
/Columns
/asp:GridView
=================

However, the currency symbol doesn't display by default and I can get the
record updated or deleted correctly. Therefore, I think there should be
something different from mine in your page. Would you give me a aspx
template so that I can test against it?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



--------------------
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: {0:c} causes input string not in correct format exception
Date: Mon, 19 Nov 2007 20:43:58 -0500

I've seen many posts complaining about this, but none with a
solution.....

I have a GridView that is bound to a SQLDataSource and working just fine,
except that when I change the DataFormatString on one of my columns that
is
displaying a smallmoney value from SQL (converted to double by .NET
Framework) to {0:c}, I get an Input String Was Not In Correct Format
exception when I attempt to delete a record. Interestgly, editing works
just fine.

I know that the problem is that when the delete takes place, the field
contains something like $299.95, which is clearly not a double or
Interestingly, and thus the error. The 64,000 question is how to fix
this
so that when the delete takes place, the data is back in it's original
(unformatted) form. I've tried stripping the "$" and the "," out of the
value in the RowDeleting event handler to no avail.

Any ideas?







Reply With Quote
  #5  
Old   
Scott M.
 
Posts: n/a

Default Re: {0:c} causes input string not in correct format exception - 11-21-2007 , 10:34 PM



Hi Steven,

It looks the same as mine, but if you run it and don't see the smallmoney
data formatted as a currency, then you must have another problem. We can't
get to my question until you can get that far. I didn't do anything special
just bound a GridView to SQL data that has a smallmoney field and chose to
take that bound column and format it as a currency. That part works like a
charm.

-Scott


"Steven Cheng[MSFT]" <stcheng (AT) online (DOT) microsoft.com> wrote

Quote:
Hi Scott,

Here is the aspx template of my test page

price column is the one of smallmoney type in SQL Express:

=======================
form id="form1" runat="server"
div
asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
DeleteCommand="DELETE FROM [sm_tb] WHERE [id] = @id"
InsertCommand="INSERT INTO [sm_tb] ([name], [price]) VALUES (@name,
@price)"
SelectCommand="SELECT [id], [name], [price] FROM [sm_tb]"
UpdateCommand="UPDATE [sm_tb] SET [name] = @name, [price] = @price WHERE
[id] = @id"
DeleteParameters
asp:Parameter Name="id" Type="Int64" /
/DeleteParameters
UpdateParameters
asp:Parameter Name="name" Type="String" /
asp:Parameter Name="price" Type="Decimal" /
asp:Parameter Name="id" Type="Int64" /
/UpdateParameters
InsertParameters
asp:Parameter Name="name" Type="String" /
asp:Parameter Name="price" Type="Decimal" /
/InsertParameters
/asp:SqlDataSource
asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1"
Columns
asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" /
asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" /
asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" /
asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" /
/Columns
/asp:GridView

/div
/form
===========================

Anything I should changed to match your case?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.










--------------------
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: Re: {0:c} causes input string not in correct format exception
Date: Tue, 20 Nov 2007 00:22:04 -0500


Is this what you want Steven:

asp:BoundField DataField="RetailPrice"
HeaderText="RetailPrice" SortExpression="RetailPrice"
DataFormatString="{0:c}" /

This does cause my displayed amounts to be formatted as currency, which is
a
"catch 22" since now when I try to delete, the value in the bound field is
not the same as it was when it was loaded into the gridview. Now, the
value
in this column is no longer compatible with a decimal, double or
smallmoney
and so the delete attempt fails.

You mention that you are not seeing your smallmoney SQL amount formatted
as
a currency amount, which you should be, so I think you don't have your
test
set up correctly.

-Scott


"Steven Cheng[MSFT]" <stcheng (AT) online (DOT) microsoft.com> wrote in message
news:%23ZQDxBzKIHA.5204 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Hi Scott,

From your description, you're encountering some "input string incorrect
format ..." error when deleting record in GridView(with DataFormatString
set in column), right?

According to the setting you mentioned, I've performed a simple test
with
the following things:


* use a simple SQL Express table with a column(of "smallmoney" type)
* in ASPX page, you SqlDataSource to connect that table(enable edit,
delete)
* in GridView, enable Edit,Delete and also apply the following
formatstring
to the boundField(of that smallmoney column)

"{0:c}"


============
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1"
Columns
asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" /
asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" /
asp:BoundField DataField="name" HeaderText="name" SortExpression="name"
/
asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" DataFormatString="{0:c}" /
/Columns
/asp:GridView
=================

However, the currency symbol doesn't display by default and I can get
the
record updated or deleted correctly. Therefore, I think there should be
something different from mine in your page. Would you give me a aspx
template so that I can test against it?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



--------------------
Reply-To: "Scott M." <smar (AT) nospam (DOT) nospam
From: "Scott M." <smar (AT) nospam (DOT) nospam
Subject: {0:c} causes input string not in correct format exception
Date: Mon, 19 Nov 2007 20:43:58 -0500

I've seen many posts complaining about this, but none with a
solution.....

I have a GridView that is bound to a SQLDataSource and working just
fine,
except that when I change the DataFormatString on one of my columns that
is
displaying a smallmoney value from SQL (converted to double by .NET
Framework) to {0:c}, I get an Input String Was Not In Correct Format
exception when I attempt to delete a record. Interestgly, editing works
just fine.

I know that the problem is that when the delete takes place, the field
contains something like $299.95, which is clearly not a double or
Interestingly, and thus the error. The 64,000 question is how to fix
this
so that when the delete takes place, the data is back in it's original
(unformatted) form. I've tried stripping the "$" and the "," out of the
value in the RowDeleting event handler to no avail.

Any ideas?








Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.