用postGIS向postgresql插入空间数据

    首先新建项目后引用Npgsql,定义连接参数

 

string strConn = @"SERVER=127.0.0.1;DATABASE=template_postgis;USERID=postgres;PASSWORD=111";
private void btnConnectPostsql_Click(object sender, EventArgs e)
{
string sql = "INSERT INTO table_name (the_geom) VALUES (ST_GeomFromText('MULTILINESTRING((1 1,2 3,3 4,3 2),(3 2,3 1))',-1));";
ExecuteScalar(sql)
}

public object ExecuteScalar( string sql)
{
IDbConnection dbcon;
dbcon
= new NpgsqlConnection (strConn);
using (dbcon)
{
dbcon.Open();
IDbCommand dbcmd
= dbcon.CreateCommand();
dbcmd.CommandText
= sql;
object ob = dbcmd.ExecuteScalar();
dbcon.Close();
return ob;
}
}

 

posted @ 2010-05-21 15:46  因是因非  阅读(922)  评论(0编辑  收藏  举报