What SqlDbType enumeration should I use when my column is the Geography type? I\'m using MS SQL Server 2008 R2.
This is what I\'m looking for specifically:
When I tried to use SqlDbType.NVarChar
I received and error
Failed to convert parameter value from Geography to a String
What resolved this problem for me was to use SqlDbType.Udt
var pgeo = cmd.Parameters.Add("@GeoLocation", SqlDbType.Udt);
pgeo.UdtTypeName = "Geography";
And then later, in a loop, I set the value of the parameter:
var ss = new SqlString(objValue.ToString());
var sc = new SqlChars(ss);
var geocode = SqlGeography.STPointFromText(sc, 4326);
cmd.Parameters["@GeoLocation"].Value = geocode;
Note: this requires Microsoft.SqlServer.Types
and System.Data.SqlTypes