i am working in forms and in database its type is double and i want convert in text.
1: I have a double value as below
public double? Area {get; set;}
2:
string v = txtTarget.ToString();
Form.Area = v;
I am using this way but not works
i am working in forms and in database its type is double and i want convert in text.
1: I have a double value as below
public double? Area {get; set;}
2:
string v = txtTarget.ToString();
Form.Area = v;
I am using this way but not works
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Jan 24, 2023, 11:19 AM
Two changes,
Form.Area= Convert.ToDouble(txtArea.Text) ;
second
when in your code behind get the value as
Form.Area.Value
Vishal JoshiPosted Jan 24, 2023, 11:07 AM
Hello Garima,
To Convert Text box value to double please try below code.
As you mention Area as nullable, ToString() will not work. in this case you should try Convert.ToString(). or you can check String.IsNullOrEmpty(String).
Try the below code.
Also, review the below link for ToString vs Convert.ToString:
https://www.c-sharpcorner.com/blogs/converttostring-vs-tostring-in-c-sharp1
Thanks
Amit MohantyPosted Jan 24, 2023, 10:28 AM
To convert a string to a double using the
double.Parse()ordouble.TryParse()method.Naimish MakwanaPosted Jan 24, 2023, 10:26 AM
Your property type is double, so you need to convert v to double.
Thanks