.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 1st, 2009, 01:18 PM
wgself wgself is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 wgself User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 16 sec
Reputation Power: 0
"Input string was not in a correct format." from textbox

I have an application where data is read from a database for an editor to check, then written to another database upon approval.
The data is numeric data which displays in the textbox with the formatting $99,999 for a value of 99999 in the database.
How do I get the 99999 from the textbox to insert into the database without the formatting codes.
Thanks,
Glen

Reply With Quote
  #2  
Old May 2nd, 2009, 04:26 PM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 336 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 15 h 51 m 40 sec
Reputation Power: 12
Send a message via AIM to Bobidybob
Code:
char[] test1 = textBox1.Text.ToCharArray();
            String value = "";

            for (int i = 0; i < test1.Length; i++)
            {
                if(char.IsDigit(test1[i]))
                {
                    value += test1[i].ToString();
                }
            }


this code will take the number with formatting from the textbox and convert it to a string representation of a non-formatted number. if you want to take into account decimals (for cents) then you can change the if statement to:

Code:
if(char.IsDigit(test1[i]) || test1[i] == '.')


this will modify it to change numbers like $99,999.99 to 99999.99
__________________

Reply With Quote
  #3  
Old May 4th, 2009, 07:30 AM
wgself wgself is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 wgself User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 16 sec
Reputation Power: 0
Thanks Bob,
That is roughly the way I have been doing it for over twenty years, I was looking for a .net library call that would take less code as I need to do it hundreds of times.
I found:
Decimal.Parse(textbox1.Text, NumberStyles.Currency) which does it in one line.
Thanks,
Glen

Quote:
Originally Posted by Bobidybob
Code:
char[] test1 = textBox1.Text.ToCharArray();
            String value = "";

            for (int i = 0; i < test1.Length; i++)
            {
                if(char.IsDigit(test1[i]))
                {
                    value += test1[i].ToString();
                }
            }


this code will take the number with formatting from the textbox and convert it to a string representation of a non-formatted number. if you want to take into account decimals (for cents) then you can change the if statement to:

Code:
if(char.IsDigit(test1[i]) || test1[i] == '.')


this will modify it to change numbers like $99,999.99 to 99999.99

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > "Input string was not in a correct format." from textbox


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap