-1

I've searched around and I've seen you can access the latitude with myGeography.Lat but it doesn't seem to work when trying to read to sqldatareader, this is what I'm trying:

String sql = "SELECT * FROM myTable WHERE myGeography.STDistance(geography::Point(somelatitude, somelongitude, 4326)) <somerange 

SqlDataReader reader = command.ExecuteReader()

int lat,long    
lat = reader["myGeography.Lat"]    
long = reader["myGeography.Long"] 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

4

SQL Geography is a data type that converts to Microsoft.SqlServer.Types.SqlGeography. Assuming myGeography is a geography, you can do it this way:

Microsoft.SqlServer.Types.SqlGeography geo = (Microsoft.SqlServer.Types.SqlGeography)reader.GetValue["myGeography"];
int long = geo.Long;
int lat = geo.Lat;
Ctznkane525
  • 7,297
  • 3
  • 16
  • 40
  • I get the error cannot aply indexing [] to a expression of type method group, if i remove getvalue it gives me a exeption – João Marques Jan 10 '18 at 03:46