9
votes

SqlDbType et géographie

Qu'est-ce que SqlDbType énumération dois-je utiliser ma colonne est le type de géographie? J'utilise MS SQL Server 2008 R2.

est ce que je cherche précisément: p>

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


0 commentaires

3 Réponses :


0
votes

Mise à jour strong>

Essayez ceci: p>

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


0 commentaires

13
votes

SqlGeography code> est mis en œuvre comme un type défini par l'utilisateur CLR par SQL Server, de sorte que vous pouvez faire quelque chose un peu comme:

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


1 commentaires

Il y a aussi un paquet NuGet avec l'ensemble nécessaire: Microsoft.SqlServer.Types (Spatial) < / a>



0
votes

Quand j'ai essayé d'utiliser SqlDbType.NVarChar code> J'ai reçu et erreur

a échoué à convertir la valeur du paramètre de la géographie à une chaîne p> Blockquote>

Que résolu ce problème pour moi était d'utiliser SqlDbType.Udt code> p>

var ss = new SqlString(objValue.ToString());
var sc = new SqlChars(ss);
var geocode = SqlGeography.STPointFromText(sc, 4326);
cmd.Parameters["@GeoLocation"].Value = geocode;


0 commentaires