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.????);
3 Réponses :
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();
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();
}
Il y a aussi un paquet NuGet avec l'ensemble nécessaire: Microsoft.SqlServer.Types (Spatial) < / a>
Quand j'ai essayé d'utiliser 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.NVarChar code> J'ai reçu et erreur
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;