Converting text to C # number to write to DB

1

I'm using this conversion to get the string of txtvalor.text and transform it to a value like this: 1.500,80

curso.Valor = double.Parse(txtValor.Text);

Example I type 1,500,80. And I'd like you to write to the database as well, in the MySQL database.

    
asked by anonymous 06.08.2014 / 20:38

2 answers

2

Avoid using text fields in the DB to store numeric values. In addition to being a bad practice (unless there is a strong purpose for it), it increases the size of the database and makes the searches much harder. It also causes a drop in performance. To write the value entered in your question (1,500,80), after doing the conversion in C # to DOUBLE (I advise you to use DECIMAL instead of DOUBLE), save the value in a NUMERIC type field in MySQL. >     

12.08.2014 / 23:35
0

Formatting is part of a view (View) aspect, ie the most reusable way would be to write the corresponding numeric value in the database and format in the best way on each of the fronts of the application.

But if you really want to force the recording, change the field type in BD to varchar (or other textual type), format it in the application and then record. When you retrieve the value it has already become formatted.

    
09.08.2014 / 00:39