Database insertion problem - SQL

Asked

Viewed 129 times

1

Follows the code:

Update command works:

int noOfRowUpdated = ctx.Database.ExecuteSqlCommand("Update Mapa set Geo = geography::Point(47.65100, -122.34900, 4326) where Id= 1");

What does not work is Insert command:

int noOfRowInserted = ctx.Database.ExecuteSqlCommand("INSERT into Mapa(Geo) values('geography::Point(47.65100, -122.34900, 4326)')");

I get that mistake:

A . NET Framework error occurred During Execution of user-defined routine or Aggregate "Geography": System.Formatexception: 24114: the label Geography::Point(47. in the WKT (well-known text) input is not valid. Valid labels are: POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON and FULLGLOBE (Data Type only Geography). System.Formatexception: Microsoft.SqlServer.Types.OpenGisTypes.Parselabel(String input) in Microsoft.SqlServer.Types.WellKnownTextReader.Parsetaggedtext(Opengistype type) in Microsoft.SqlServer.Types.WellKnownTextReader.Read(Opengistype type, Int32 srid) in Microsoft.SqlServer.Types.SqlGeography.Parsetext(Opengistype type, Sqlchars taggedText, Int32 srid) in Microsoft.SqlServer.Types.SqlGeography.Geographyfromtext(Opengistype type, Sqlchars taggedText, Int32 srid) in Microsoft.SqlServer.Types.SqlGeography.Parse(Sqlstring s) . The statement has been terminated.

1 answer

3


Single quotes have to start before the ('Point(... not before geography::. If not, try to remove them.

Like in this example microsoft:

.
.
.

INSERT INTO SpatialTable (GeogCol1)  
VALUES (geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656 )', 4326));

.
.
.

See that?! No quotation marks involving the keyword Geography.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.