using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//添加命名空间
using Microsoft.SqlServer.Types;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Data;namespace SQL.NET
{
    class Program
    {
        static void Main(string[] args)
        {
            //定义一个多边形
            var polygon = SqlGeography.STGeomFromText(
                new SqlChars(
                new SqlString("POLYGON ((-114.01611328125 42.0003251483162, -114.0380859375 42.0003251483162,"
                    + "-113.994140625 37.0200982013681, -109.05029296875 37.0200982013681, -109.09423828125 41.0130657870063, "
                    + "-111.07177734375 41.0462168145206, -111.07177734375 42.0003251483162, -114.01611328125 42.0003251483162))",
                    111)),
                    4326);            var sql = "insert Cities (CityName,CityLocation) values ('test','" + polygon.ToString() + "')";            InsertToDB(sql);
        }        private static void InsertToDB(string sql)
        {
            using (var conn = new SqlConnection(ConfigurationManager.AppSettings["SQL2008"]))
            {
                if (conn.State == ConnectionState.Closed) conn.Open();
                using (var cmd = new SqlCommand(sql, conn))
                {
                    int row = cmd.ExecuteNonQuery();
                }
            }
        }
    }
}