Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SqlDbType与地理_Sql_Sql Server 2008_Ado.net - Fatal编程技术网

SqlDbType与地理

SqlDbType与地理,sql,sql-server-2008,ado.net,Sql,Sql Server 2008,Ado.net,当我的列是地理类型时,应该使用什么SqlDbType枚举?我正在使用MS SQL Server 2008 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";

当我的列是地理类型时,应该使用什么SqlDbType枚举?我正在使用MS SQL Server 2008 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.????);

更新

试试这个:

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

取自

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几何体查看器的使用将对桌面或web都有帮助


您需要引用SQL Server安装/100/SDK/Assemblies中的Microsoft.SqlServer.Types.dll,以直接使用SQLGeometry或SQLGeography。

当我尝试使用
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

还有一个包含所需程序集的NuGet包: