korrowan
korrowan

Reputation: 579

How to pass decimal value from textbox to parameter

I am trying to create a save Button and it includes 2 values in TextBox controls that are considered currency in sql. They are decimal in the TextBox. How do I pass the value? I tried this to no avail:

decimal taxOpen = Convert.ToDecimal(taxOpenTextBox).Text;

Any help on the correct syntax would be great.

Upvotes: 0

Views: 4611

Answers (2)

Femaref
Femaref

Reputation: 61457

You need to access the Text property. You also should use TryParse, which returns false instead of throwing an exception if the parse fails:

decimal value;

if(!decimal.TryParse(taxOpenTextBox.Text, 
                     NumberStyles.Currency, 
                     NumberFormatInfo.InvariantInfo, 
                     out value))
  MessageBox.Show("Please enter a valid number");

The needed things are found in System.Globalization.

Upvotes: 1

Tim
Tim

Reputation: 5421

You need to get the value of the taxOpenTextBox, not the box itself.

Upvotes: 0

Related Questions