当我的列是地理类型时,我应该使用什么SqlDbType枚举?我使用的是MS SQL Server2008 R2。
这就是我特别要找的:
// 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.????);发布于 2010-09-17 23:29:38
更新
试试这个:
//define parameter
command.Parameters.Add("@shape", SqlDbType.NVarChar);
//
//code in between omitted
//
//set value of parameter
command.Parameters["@shape"].Value = feature.Geometry.AsText();摘自Inserting SQL 2008 Geometry With a SqlCommand
发布于 2010-10-19 16:10:16
SqlGeography是由SQL Server作为CLR用户定义类型实现的,因此您可以执行类似以下操作:
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();
}如果它是一个桌面应用程序,那么它就容易得多了。在SQL Geometry viewer的Code Project中有一个很好的例子,它对桌面或web都有帮助。
要直接使用SQLGeometry或SQLGeography,需要引用位于SQL Server Install/100/SDK/Assemblies中的Microsoft.SqlServer.Types.dll。
发布于 2019-10-18 02:02:20
当我尝试使用SqlDbType.NVarChar时,我收到错误消息
无法将参数值从地理位置转换为字符串
为我解决这个问题的是使用SqlDbType.Udt
var pgeo = cmd.Parameters.Add("@GeoLocation", SqlDbType.Udt);
pgeo.UdtTypeName = "Geography";然后,在一个循环中,我设置了参数的值:
var ss = new SqlString(objValue.ToString());
var sc = new SqlChars(ss);
var geocode = SqlGeography.STPointFromText(sc, 4326);
cmd.Parameters["@GeoLocation"].Value = geocode;注意:这需要Microsoft.SqlServer.Types和System.Data.SqlTypes
https://stackoverflow.com/questions/3736666
复制相似问题