views:

50

answers:

3

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:

// ADO.net - what do I use for the SqlDbType when it's defined 
// as Geography in the stored proc
SqlCommand command = new SqlCommand();
command.CommandText = "dbo.up_Foobar_Insert";
command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("@SomeGeographyType", SqlDbType.????);
A: 

Update

Try this:

//define parameter
command.Parameters.Add("@shape", SqlDbType.NVarChar);
//
//code in between omitted
//
//set value of parameter
command.Parameters["@shape"].Value = feature.Geometry.AsText();

Taken from Inserting SQL 2008 Geometry With a SqlCommand

Denis Valeev
LMGTFY is in effect **BANNED** from SO. Just don't.
Oded
Mwahahahahahaha!! Are you serious?
Denis Valeev
Thanks Denis....and here I thought SO was somewhere to ask programming related questions.
Dismissile
@Dismissile I found it funny to sneak a surprise in that link; I believe some members of SO community are too sensitive to such petty issues. I hope this helps you resolve the problem.
Denis Valeev
Yes, I am serious: http://meta.stackoverflow.com/questions/15650/ban-lmgtfy-let-me-google-that-for-you-links
Oded
+1  A: 

If it is a desktop application you've got it quite a bit easier. There is a good example at the Code Project of an SQL Geometry viewer that will help for both desktop or web.

You need to reference Microsoft.SqlServer.Types.dll, found at SQL Server Install/100/SDK/Assemblies to use SQLGeometry or SQLGeography directly.

Rowland Shaw
A: 

SqlGeography is implemented as a CLR user defined type by SQL Server, so you can do something a little like:

SqlGeography geo = // Get the geography from somewhere...

using (SqlCommand command = 
    new SqlCommand(@"dbo.up_Foobar_Insert", connection))
    command.Parameters.Add(new SqlParameter("@Point", geo) { UdtTypeName = "Geography" });
    command.ExecuteNonQuery();
}
Rowland Shaw