2010-09-17 7 views
8

¿Qué enumeración SqlDbType debo usar cuando mi columna es del tipo Geografía? Estoy usando MS SQL Server 2008 R2.SqlDbType y Geography

Esto es lo que estoy buscando específicamente:

// 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.????); 

Respuesta

0

actualización

Prueba esto:

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

Tomado de Inserting SQL 2008 Geometry With a SqlCommand

11

SqlGeography es im complementado como usuario CLR tipo definido por SQL Server, por lo que se puede hacer algo un poco como:

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(); 
} 

Si se trata de una aplicación de escritorio que lo tienes un poco más fácil. Hay un buen ejemplo en el Code Project de un visor de SQL Geometry que ayudará tanto en el escritorio como en la web.

Debe hacer referencia a Microsoft.SqlServer.Types.dll, que se encuentra en SQL Server Install/100/SDK/Assemblies para usar SQLGeometry o SQLGeography directamente.

+2

También hay un paquete NuGet con el conjunto requerido: [Microsoft.SqlServer.Types (Spatial)] (http://www.nuget.org/packages/Microsoft.SqlServer.Types/) – Sam

Cuestiones relacionadas