0

I have a table in SQL Server with a column of type SqlGeometry. I am loading the DataTable, then I'm executing DataTable.WriteXml. Unfortunately, the data from the column of type SqlGeometry is not written out.

        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");

Instead of a set of data is only:

<?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>
(...)

How to do to be saved all the geometric data?

promwand
  • 11
  • 2
  • Please add the code to your Q. – Amin Negm-Awad Jul 04 '16 at 15:09
  • When you use WriteXml() the DataTable must have a name. So when you call the constructor add a name as a parameter in the call to the constructor or use the property TableName to assign a value. – jdweng Jul 04 '16 at 16:02

0 Answers0