C#SqlGeometry DataTable.WriteXml

时间:2016-07-04 15:05:04

标签: c# sql-server xml sqlgeometry

我在SQL Server中有一个表SqlGeometry列的表。我正在加载DataTable,然后我正在执行DataTable.WriteXml。不幸的是,类型SqlGeometry的列中的数据未被写出。

        DataTable dt = new DataTable();
        string tabela = string.Empty;
        tabela = "x.yz";
        string sqlConString = @"Server=xxx.xxx.xxx.xxx\SQLEXPRESS2012;Database=xxx;User Id=xx;Password =xx; ";
        string sqlQuery = String.Format("select * from {0}",tabela);
        using (SqlConnection sqlCon = new SqlConnection(sqlConString))
        {
            SqlCommand sqlCmd = new SqlCommand(sqlQuery, sqlCon);
            try
            {
                sqlCon.Open();
                SqlDataReader dr = sqlCmd.ExecuteReader();
                dt.Load(dr);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        dt.TableName = "123";
        dt.WriteXml(@"j:\tmp\3.xml");

仅代替一组数据:

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <_x0031_23>
    <FeatId>5662</FeatId>
    (...)
    <geom xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <STSrid>2180</STSrid>
    </geom>
  </_x0031_23>
  <_x0031_23>
    <FeatId>5663</FeatId>
(...)

如何保存所有几何数据?

0 个答案:

没有答案