如果不借助ODAC的自定義數據類型,那麼也可以使用Oracle Spatial的幾個內置SQL函數來實現SDO_Geometry對象的操作
這種方法需要在數據庫端對所有數據進行一次轉換(不管是在select 還是insert時),有些情況下會對性能和執行時間有比較大的影響,需要注意
OracleCommand cmd = new OracleCommand(@"SELECT geo.get_wkb() FROM geoinfo WHERE id= '12' ", con); con.Open(); byte[] wkb = (byte[])cmd.ExecuteScalar();
OracleCommand cmd = new OracleCommand(@"SELECT geo.get_wkt() FROM geoinfo WHERE id= '12' ", con); con.Open(); string wkt = (string)cmd.ExecuteScalar();
OracleCommand cmdGeom = new OracleCommand(@"insert into geoinfo values (13,sdo_geometry(:geom,31297))", con); //31297為srid,實際使用時應替換成自己的srid OracleParameter p1 = new OracleParameter(":geom",OracleDbType.Blob); p1.Value = wkb; //wkb為byte[] cmdGeom.Parameters.Add(p1); con.Open(); int i = cmdGeom.ExecuteNonQuery(); con.Close();
OracleCommand cmdGeom = new OracleCommand(@"insert into geoinfo values (13,sdo_geometry(:geom,31297))", con); OracleParameter p1 = new OracleParameter(":geom",OracleDbType.Clob); p1.Value = wkt; //wkt為string cmdGeom.Parameters.Add(p1); con.Open(); int i = cmdGeom.ExecuteNonQuery(); con.Close();