|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
{0:c} causes input string not in correct format exceptionI'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? 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- Show quoteHide quote >Reply-To: "Scott M." <smar@nospam.nospam> >From: "Scott M." <smar@nospam.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? > > 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 Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:%23ZQDxBzKIHA.5204@TK2MSFTNGHUB02.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > > ================================================== > > > This posting is provided "AS IS" with no warranties, and confers no > rights. > > > > -------------------- >>Reply-To: "Scott M." <smar@nospam.nospam> >>From: "Scott M." <smar@nospam.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? >> >> > 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. -------------------- Show quoteHide quote >Reply-To: "Scott M." <smar@nospam.nospam> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif>From: "Scott M." <smar@nospam.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]" <stch***@online.microsoft.com> wrote in message >news:%23ZQDxBzKIHA.5204@TK2MSFTNGHUB02.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 >> Show quoteHide quote >> 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/subscriptions/support/default.aspx. >> >> ================================================== >> >> >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> >> >> >> -------------------- >>>Reply-To: "Scott M." <smar@nospam.nospam> >>>From: "Scott M." <smar@nospam.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? >>> >>> >> > > 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 Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:zUXipNCLIHA.7800@TK2MSFTNGHUB02.phx.gbl... > 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@nospam.nospam> >>From: "Scott M." <smar@nospam.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]" <stch***@online.microsoft.com> wrote in message >>news:%23ZQDxBzKIHA.5204@TK2MSFTNGHUB02.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. >>> >>> ================================================== >>> >>> >>> This posting is provided "AS IS" with no warranties, and confers no >>> rights. >>> >>> >>> >>> -------------------- >>>>Reply-To: "Scott M." <smar@nospam.nospam> >>>>From: "Scott M." <smar@nospam.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? >>>> >>>> >>> >> >> >
Reload/refresh data in datagrid
GridView is making two of each column Rendering a GridView Updating SelectedIndex after delete wrap text in datagrid cell wrapping text in datagrid Making an entire column visible/not visible. Programattically setting gridview to edit mode Hiding grid columns based on some value in row DataView Borders |
|||||||||||||||||||||||