Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:36:08+00:00 2026-06-04T00:36:08+00:00

I have a double values in C# and I want to put them into

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:36:10+00:00Added an answer on June 4, 2026 at 12:36 am

    This should work:

      using (MySqlConnection con = new MySqlConnection("server=localhost;database=Data_GPS;uid=root;pwd=******")
      {
            con.Open();
            using (MySqlCommand  cmd = new MySqlCommand("insert into Data values (null, @Parname , @Parname2, @Parname3);", con)
            {
                // change MySqlDbType.Double to reflect the real data type in the table.
                cmd.Parameters.Add("@Parname", MySqlDbType.Double).Value = deciLat;
                cmd.Parameters.Add("@Parname2", MySqlDbType.Double).Value = deciLon;
                cmd.Parameters.Add("@Parname3", MySqlDbType.DateTime).Value = time;
                cmd.ExecuteNonQuery();
            }
      }
    

    always put your Connections and Commands inside using to make sure that you free all objects without the need of explicit Dispose() command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some double values I want to convert to a string with this
I have table which contains double values stored in mysql database ...I need to
I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
I have a string that contains a known number of double values. What's the
I have a problem when trying to retrieve values from an array. I want
I have a method that i want to return as a double with 8
I have a list of double values, I want to Round a variable's value
I have a list of double values that I don't know the range of
I have double values which I would like to convert to String values with
I have a set of three double values as part of an anonymous expression

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.