在mySQL中存储和收集double值

时间:2014-01-12 21:20:13

标签: c# mysql

自从星期五以来,我一直在使用这些代码,我只是不能让它工作,我想将两个double值存储到一个表中,而我得到的最接近的是丢失坐标上的值的小数点好(它在地图上的错误)。

我的商店方法如下所示:

   public bool saveLatLong(Double lat, Double lon, String mapID)
{
    bool worked = true;
    String myConnection = WebConfigurationManager.ConnectionStrings["webbased"].ConnectionString;
    MySqlConnection myConn = new MySqlConnection(myConnection);
    String strSQL = "UPDATE map SET Latitud = '"+lat+"' AND Longitud = '"+lon+"' WHERE ID = '" + mapID + "';";
    MySqlCommand myCommand = new MySqlCommand();
    myCommand.Connection = myConn;
    myCommand.CommandText = strSQL;
    try
    {
        myConn.Open();
        myCommand.ExecuteNonQuery();
    }
    catch (MySqlException myE)
    {
        worked = false;
        Console.WriteLine("It's all gone south!: " + myE.Message);
    }
    finally
    {
        myConn.Close();
    }
    return worked;
}

在调试mysql字符串看起来没问题我相信:UPDATE map SET Latitud = '57,7141957471802' AND Longitud = '11,9798612594604' WHERE ID = '563-34';

我的get方法如下所示:

   public void getCordinates(String mapID, out double latitude, out double longitude)
{
    double nlat = 0.0;
    double nlon = 0.0;
    String myConnection = WebConfigurationManager.ConnectionStrings["webbased"].ConnectionString;
    MySqlConnection myConn = new MySqlConnection(myConnection);
    String strSQL = "SELECT Latitud,Longitud FROM cases WHERE ID = '"+mapID+"';";
    MySqlCommand myCommand = new MySqlCommand();
    myCommand.Connection = myConn;
    myCommand.CommandText = strSQL;
    try
    {
        myConn.Open();
        MySqlDataReader myReader;
        myReader = myCommand.ExecuteReader();

        while (myReader.Read())
        {
            if (myReader.GetValue(0).Equals(DBNull.Value)) { nlat = 0.0; } else { nlat = myReader.GetDouble(0); }
            if (myReader.GetValue(1).Equals(DBNull.Value)) { nlon = 0.0; } else { nlon = myReader.GetDouble(1); }                 
        }

    }
    catch (MySqlException myE)
    {
        Console.WriteLine("It's all gone south!: " + myE.Message);
    }
    finally
    {
        myConn.Close();
    }
    latitude = nlat;
    longitude = nlon;
}

我尝试过什么,我只得到0.0作为结果,我只是无法弄清楚为什么,我相信我已经尝试了一切,我不能在问题上得到正面或反面。我怀疑我在get方法中运行的getDouble命令存在问题,但我不知道还能做什么。

我很感激任何想法或见解,问题是为什么我无法掌握数据库中的值。

0 个答案:

没有答案