I have a double values in C# and I want to put them into the database.
Problem is that I have tried all the formats in the database and still I am getting a number to sign DOT.
For example if I have a number 45.548 it will be saved in database as 45
When I am debugging the code I can see that value is really sent as 45.548.
Here is my code so you can see what might went wrong:
MySqlConnection con = null;
MySqlCommand cmd = null;
con = new MySqlConnection("server=localhost;database=Data_GPS;uid=root;pwd=******");
con.Open();
cmd = new MySqlCommand("insert into Data values (null, ?Parname , ?Parname2, ?Parname3);", con);
cmd.Parameters.AddWithValue("?Parname", deciLat);
cmd.Parameters.AddWithValue("?Parname2", deciLon);
cmd.Parameters.AddWithValue("?Parname3", time);
cmd.ExecuteNonQuery();
con.Close();
I have tried to change format in the database with float, double, decimal, varchar and still I am not getting the right number.
Thank you
EDIT:
This is how I fill my decimal values:
string[] arrLon = Lon.Split(new char[] { '°', '"' }, StringSplitOptions.RemoveEmptyEntries);
double dblLon = double.Parse(arrLon[0]) + double.Parse(arrLon[1], new System.Globalization.NumberFormatInfo()) / 60;
double deciLon = arrLon[2] == "E" ? dblLon : -dblLon;
string[] arrLat = Lat.Split(new char[] { '°', '"' }, StringSplitOptions.RemoveEmptyEntries);
double dblLat = double.Parse(arrLat[0]) + double.Parse(arrLat[1], new System.Globalization.NumberFormatInfo()) / 60;
double deciLat = arrLat[2] == "N" ? dblLat : -dblLat;
This should work:
always put your Connections and Commands inside
usingto make sure that you free all objects without the need of explicitDispose()command.