数据表中的C#地理列 [英] c# geography column in datatable

查看:41
本文介绍了数据表中的C#地理列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个数据表,我想添加一列以地理格式存储纬度和经度坐标,然后在sql server中批量复制。我应该以哪种格式创建数据列?

I have a datatable in c# and I want to add a column to store latitude and longitude coordinates in geography format to bulkcopy in sql server after that. In what format should I create the datacolumn for this? Can you guide me please?

推荐答案

我们必须使用位于
下的引用dll C:\ \程序文件(x86)\Microsoft SQL Server\100\SDK\程序集\Microsoft.SqlServer.Types.dll

We have to use the reference dll that is located under "C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll"

using Microsoft.SqlServer.Types;

之后,我们可以在数据表中创建该列,存储一些数据,然后通过以下方式将其成功发送到sql server bulkcopy

After that we can create the column in datatable, store some data and successfully send them to sql server via bulkcopy

DataTable dataTable = new DataTable();
dataTable.Columns.Add("Geom", typeof(SqlGeometry));

DataRow newRow = datatable.NewRow();
newRow["Geom"] = SqlGeometry.Point(lat, lon, 4326);

datatable.Rows.Add(newRow);

SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(connection);
sqlBulkCopy.DestinationTableName = "MySpatialDataTable";
sqlBulkCopy.WriteToServer(dataTable);

这篇关于数据表中的C#地理列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆