IF object_id (' dbo. Spatialtable ', ' U ') is not NULL
DROP TABLE dbo. spatialtable;
GO
CREATE TABLE spatialtable
(id int IDENTITY (),
GeomCol1 geometry,
GeomCol2 as Geomcol1.stastext ());
GO
INSERT into spatialtable (GeomCol1)
VALUES (Geometry::stgeomfromtext (' LINESTRING (100 100, 20 180, 180 180) ', 0));
INSERT into spatialtable (GeomCol1)
VALUES (Geometry::stgeomfromtext (' POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0) ', 0));
GO
INSERT into spatialtable (GeomCol1)
VALUES (Geometry::stgeomfromtext (' LINESTRING (116.387112 39.920977,116.385243 39.913063,116.394226 39.917988,116.401772 39.921364,116.41248 39.927893,116.387112 39.920977) ', 4326)
Database db = Databasefactory.createdatabase ();
DbCommand dbcmd = db. Getsqlstringcommand ("Select GeomCol1 from spatialtable WHERE id=4");
using (IDataReader reader = db. ExecuteReader (dbcmd))
{
if (reader. Read ())
{
SqlGeometry o = reader[0] as SqlGeometry;
}
}
SqlGeometry Geo = Sqlgeometry.parse ("POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0)");
DataSet ds = db. ExecuteDataset (dbcmd);
SqlGeometry Geo = ds. Tables[0]. ROWS[0][1] as SqlGeometry;
SqlDouble area = Geo. Starea ();
dbcmd = db. Getsqlstringcommand (@ "INSERT into spatialtable (GeomCol1) VALUES (@p)");
Sqlgeometrybuilder sb = new Sqlgeometrybuilder ();
Sb. Setsrid (4326);
Sb. Begingeometry (Opengisgeometrytype.polygon);
Sb. BeginFigure (0, 0);
Sb. AddLine (150, 0);
Sb. AddLine (150, 150);
Sb. AddLine (0, 150);
Sb. AddLine (0, 0);
Sb. Endfigure ();
Sb. Endgeometry ();
dbcmd = db. Getsqlstringcommand (String. Format ("INSERT into Spatialtable" (GeomCol1) VALUES (Geometry::stgeomfromtext (' {0} ', {1})) "
, SB. Constructedgeometry.tostring (), 4326));
Db. Addinparameter (dbcmd, "@p", Dbtype.binary, sb.) Constructedgeometry.stasbinary (). Buffer);
int cnt = db. ExecuteNonQuery (dbcmd);
Get the system's coordinates (in SQL Server) from this sql: Select * from Sys.spatial_reference_systems
SQL Server Geometry Type action Note