我正在弄清楚如何获取地理数据(纬度/经度)并使用地理列将其添加到 SQL 数据库中。我正在参考Microsoft.SqlServer.Types
获取SqlGeographyBuilder
我还应该补充一点,这是在 SQL2008r2 上
我的 C# 项目也在使用 .Net 4.0
这只是我在 C# 代码中使用的代码片段:
SqlParameter param21 = new SqlParameter();
param21.ParameterName = "@Shape";
param21.UdtTypeName = "Geography";
param21.SqlDbType = System.Data.SqlDbType.Udt;
param21.Size = 1;
SqlGeographyBuilder sqlGeogBuild = new SqlGeographyBuilder();
SqlGeography sqlGeog = null;
sqlGeogBuild.SetSrid(4267);
if (inputReader[parmLatColumnName].ToString().Length > 0 && inputReader[parmLonColumnName].ToString().Length > 0)
{
sqlGeogBuild.BeginGeography(OpenGisGeographyType.Point);
sqlGeogBuild.BeginFigure(float.Parse(inputReader[parmLatColumnName].ToString()), float.Parse(inputReader[parmLonColumnName].ToString()));
sqlGeogBuild.EndFigure();
sqlGeogBuild.EndGeography();
sqlGeog = sqlGeogBuild.ConstructedGeography;
param21.Value = sqlGeog;
}
else
{
param21.Value = DBNull.Value;
}
sqlComm.Parameters.Add(param21);
当我使用分析器时,我发现我的查询看起来像这样:
declare @p21 sys.geography
set @p21=convert(sys.geography,0xE6100000010C00000080B0374040000000806BD057C0)
exec insPoints @stCty=N'31256',@InstrumentType=N'''ogVal''',@FileDate='2008-01-03 00:00:00',@EntryNumber=N'''500''',@Vol=N'NULL',@Page=N'NULL',@Lessor=N'''name''',@Lessee=N'''company name''',@InstrumentDate='2000-01-12 00:00:00',@Term=3,@TermType=N'''Years''',@Expiration='2010-07-12 00:00:00',@Royalty=0.000100000,@GrossAcres=1.000000000,@AgencyId=N'NULL',@Agency=N'''Fee''',@EffDate=NULL,@Survey=N'''A500,A06,A700,A400,A900''',@Longitude=-91.000000000,@Latitude=30.000000000,@Shape=@p21
当我将它作为地理类型传递时,为什么它会将其转换为地理类型?