string SQLString = " insert into CPAttribute(Geom) values (@xyValue)";
sds.InsertParameters.Add("xyValue", "geometry::STPointFromText('POINT(" + EValue + " " + NValue + ")',0)");
但會出現下面這個錯誤訊息。
***********************************************************************
執行使用者自訂常式或彙總 "geometry" 時,發生 .NET Framework 錯誤:
System.FormatException: 24114: 在輸入的 well-known text (WKT) 中的標籤 geometry::STPointFro 無效。有效的標籤為 POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON 或 GEOMETRYCOLLECTION。
***********************************************************************
正確的寫法應該是:
string SQLString = " insert into CPAttribute(Geom) values (geometry::STPointFromText(@xyValue,@spatial_ref))";
sds.InsertParameters.Add("xyValue", "POINT(" + EValue + " " + NValue + ")");
sds.InsertParameters.Add("spatial_ref", "0");
完整測試程式碼
System.Web.UI.WebControls.SqlDataSource sds = new System.Web.UI.WebControls.SqlDataSource();
sds.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string EValue = "123";
string NValue = "45";
string SQLString = " insert into CPAttribute(Geom) values (geometry::STPointFromText(@xyValue,@spatial_ref))";
sds.InsertParameters.Add("xyValue", "POINT(" + EValue + " " + NValue + ")");
sds.InsertParameters.Add("spatial_ref", "0");
sds.InsertCommand = SQLString;
sds.Insert();
沒有留言:
張貼留言