Click here to Skip to main content
Click here to Skip to main content

TIP: Managing SqlGeography class from C#

By , 4 Sep 2010
Rate this:
Please Sign up or sign in to vote.
It took me some time to get this to work. The problem is that SqlGeography C# type, which corresponds to Geography SQL type, is considered an user-defined type (UDT) by the .net SQL library.
So, the proper way to insert or update a Geography field is something like this:
SqlGeography geo = // Get the coordinates from somewhere...

using (SqlCommand command = 
    new SqlCommand(@"UPDATE Points SET Point=@Point WHERE FeatureID='9999'", connection))
    command.Parameters.Add(new SqlParameter("@Point", geo) { UdtTypeName = "Geography" });


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jaime Olivares
Architect Freelance (
Peru Peru

Computer Electronics professional, Software Architect and senior Windows C++ and C# developer with experience in many other programming languages, platforms and application areas including communications, simulation systems, GIS, 3D graphics and mobile platform.
Also have experience in development of electronic interfaces, specially for military applications.
Currently intensively working with Visual C# 2010 and TFS.
Can be reached at

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 4 Sep 2010
Article Copyright 2010 by Jaime Olivares
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid