地理不是二进制存储



我在ASP.net中使用以下查询来保存MS SQL中的坐标:

SqlCommand cmd = new SqlCommand
    ("Insert Into Properties (nPropertyId, vcCompleteAddress, vcPostCode,
      vcAddressLine1, vcAddressLine2, vcCity, vcCountry, dLatitude,
      dLongitude, gCoordinates, dtmDateAdded, vcUserName, nPropertyTypeId, imgImage
    ) Values(
      @nPropertyId, @vcCompleteAddress, @vcPostCode, @vcAddressLine1,
      @vcAddressLine2, @vcCity, @vcCountry, @dLatitude, @dLongitude,
     geography::STGeomFromText('POINT(" + txtLongitude.Text + " " + txtLatitude.Text + ")', 4326)**, 
      @dtmDateAdded, @vcUserName, @nPropertyTypeId, @imgImage)", conn);

但是,地理数据保存为:POINT (-2.270959 52.2323256),而不是二进制。我哪里做错了?

谢谢。

当我尝试将它作为参数传递给下面的代码时,我得到了我需要将string转换为IEnumerable的错误。

SqlParameter param12 = new SqlParameter("@gCoordinates", SqlDbType.Udt);
param12.UdtTypeName = "geography";
param12.Value = txtLongitude.Text + " " + txtLatitude.Text;
cmd.Parameters.Add(param12);
param12.SqlDbType = SqlDbType.Structured;

我将纬度和经度保存为长数据类型,而不是地理位置。它使事情变得简单,一切都很完美。

最新更新