我在計算如何使用Geography數據(Lat/Lon)並將其添加到使用Geography列的SQL數據庫中。我引用Microsoft.SqlServer.Types
得到SqlGeographyBuilder
傳入地理類型和SQL轉換爲地理類型?
我還要補充一點,這是對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,@[email protected]
它爲什麼將其轉換爲一個地理類型,當我在把它當作一個地理類型?
我沒有看到任何區別。我同意,它似乎是.Net和SQL之間的差距,但我想知道什麼時候差距會消失? – webdad3
MS向'SqlDbType'枚舉中添加'geography'時。 – Stoleg