OverdueOrange
OverdueOrange

Reputation: 99

Correct Format to enter into a Geography data-type database cell

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

Answers (1)

Arockia Nirmal
Arockia Nirmal

Reputation: 777

Use geography Data Type with the correct syntax as below

syntax:

Point ( Lat, Long, SRID )

Reference 1

Reference 2

=================================================================

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

enter image description here

Upvotes: 1

Related Questions