Reputation: 99
I have created a Database using SQL Server Management Studio 2014 and have came across a problem when entering data.
The problem is that I don't know what format to enter data into a (Location) geography cell.
I am entering the Longitude and Latitude exactly like this > 54.763226, -1.386241
But get this error:
The changed value in this cell was not recognised as valid. .NET Framework Data Type: SqlGeography, Error message: Invalid cast from 'System.String' to 'Microsoft.SqlServer.Types.SqlGeography'
Please can you tell me how to add data into the Geography cell correctly?
Upvotes: 1
Views: 1556
Reputation: 777
Use geography Data Type with the correct syntax as below
syntax:
Point ( Lat, Long, SRID )
=================================================================
Sample table:
CREATE TABLE dbo.EarthquakeData
(
EarthquakeID INT IDENTITY(1,1),
EarthquakeInformation GEOGRAPHY NOT NULL
)
Inserting data:
insert into dbo.EarthquakeData (EarthquakeInformation )
values (geography::STGeomFromText(
'POINT(54.763226 -1.386241)',4326))
Viewing inserted data:
select cast(EarthquakeInformation as nvarchar(max)) from dbo.EarthquakeData
Upvotes: 1