如何在mysql表中插入一个点?

时间:2018-08-28 03:43:06

标签: point

我有一张桌子来存储客户地址。使用该地址,我正在保存几何坐标。由于某些原因,它返回错误“列'ADDRESS_LONGI_LATIT_LOCATION'不能为空”。很有可能来自““ PointFromText(@ Parameter10)”。感谢您的帮助。

这是我的代码(在C#中):

if (oMySQLConnecion.State == System.Data.ConnectionState.Open)
                {
                    string AddressLocation = "POINT(" + oUserLocation.Longitude + " " + oUserLocation.Latitudes + ")";

                    string Query = @"INSERT INTO address (" +
                                        "ADDRESS_TYPE," +
                                        "ADDRESS_STREET_ADDRESS_1," +
                                        "ADDRESS_STREET_ADDRESS_2," +
                                        "ADDRESS_CITY," +
                                        "ADDRESS_STATE," +
                                        "ADDRESS_ZIPCODE," +
                                        "ADDRESS_COUNTRY," +
                                        "ADDRESS_LONGI_LATIT_LOCATION) " + 
                                    "VALUES (" +
                                        "@Parameter3," +
                                        "@Parameter4," +
                                        "@Parameter5," +
                                        "@Parameter6," +
                                        "@Parameter7," +
                                        "@Parameter8," +
                                        "@Parameter9," +
                                        "PointFromText(@Parameter10));" +
                                    "SELECT LAST_INSERT_ID()";

                    MySqlCommand oCommand = new MySqlCommand(Query, oMySQLConnecion);
                    oCommand.Parameters.AddWithValue("@Parameter2", UserID);
                    oCommand.Parameters.AddWithValue("@Parameter3", Enum.GetName(typeof(OwnerType), oAddr.AddressType));
                    oCommand.Parameters.AddWithValue("@Parameter4", oAddr.AddressStreetAddress1);
                    oCommand.Parameters.AddWithValue("@Parameter5", oAddr.AddressStreetAddress2);
                    oCommand.Parameters.AddWithValue("@Parameter6", oAddr.AddressCity);
                    oCommand.Parameters.AddWithValue("@Parameter7", oAddr.AddressState);
                    oCommand.Parameters.AddWithValue("@Parameter8", oAddr.AddressZipCode);
                    oCommand.Parameters.AddWithValue("@Parameter9", oAddr.AddressCountry);
                    oCommand.Parameters.AddWithValue("@Parameter10", AddressLocation);
                    int sqlSuccess = oCommand.ExecuteNonQuery();
                    int AddressID = Convert.ToInt16(oCommand.LastInsertedId);
                    oMySQLConnecion.Close();

                    if (sqlSuccess > 0)
                    {
                        oDBStatusWithLastKey.Type = DBOperation.SUCCESS;
                        oDBStatusWithLastKey.Message.Add(DBMessageType.SUCCESSFULLY_DATA_INSERTED);
                    }
                    else
                    {
                        oDBStatusWithLastKey.Type = DBOperation.ERROR;
                        oDBStatusWithLastKey.Message.Add(DBMessageType.ERROR_NO_RECORDS_UPDATED);
                    }
                    oDBStatusWithLastKey.LastUpdatedKey = AddressID;
                    return oDBStatusWithLastKey;
                }
                else
                {
                    oDBStatusWithLastKey.Type = DBOperation.ERROR;
                    oDBStatusWithLastKey.Message.Add(DBMessageType.ERROR_DUE_TO_NO_DB_CONNECTION);
                    return oDBStatusWithLastKey;
                }
            }
            else
            {
                oDBStatusWithLastKey.Type = DBOperation.ERROR;
                oDBStatusWithLastKey.Message.Add(DBMessageType.ERROR_DUPLICATE_ITEM);
                return oDBStatusWithLastKey;
            }

0 个答案:

没有答案