error in windows form decimal textboxValue = decimal.Parse(textBox1.Text);

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hazboo658
    New Member
    • Oct 2016
    • 1

    error in windows form decimal textboxValue = decimal.Parse(textBox1.Text);

    Code:
    decimal textboxValue = decimal.Parse(textBox1.Text);
    I received an error in this line stating "you cant convert decimal to decimal" although I declare it in SQL as decimal.
    Last edited by Frinavale; Oct 26 '16, 05:15 PM. Reason: added code tags and corrected grammar
  • Michael Gorsich
    New Member
    • Oct 2016
    • 1

    #2
    It's not going to matter what type in your db it is, the value being parsed is coming from a textbox and, therefore, the value in the textbox has to be a valid string representation of a decimal in the current culture (ex. if textbox value uses ',' for decimal point then your Windows culture setting must use ',' for decimal point), or else you have to specify formatting with Decimal.Parse() .

    I tried your code and it worked for me with a good value for textBox1.text.

    Could you please give an actual value from your textbox that generates this error?
    Last edited by Michael Gorsich; Oct 18 '16, 12:22 PM. Reason: More info.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      It would really help if you posted the code where it Actually crashed. The code that you posted will not crash.

      It would also help if you mentioned what type of database you are connecting to and whether you are trying to retrieve information from the database or insert/update information into the database.

      Comment

      Working...