Reputation: 579
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
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