Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot serialize the DataTable. DataTable name is not set

I need to export all datatables to individual XML files and I cannot export all the rows at once because of System.OutOfMemoryException if there is a huge table. So I tried to export N rows. However WriteXml throws an exception if I use paging syntax in query.

I've tested both queries in LINQPad, they are ok.

System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.

  // The first query causes exception
  string oraQueryGetTableData = "SELECT * FROM (SELECT t0.* FROM MY_TABLE t0) WHERE ROWNUM <= 100";

  // The second query runs without any error
  //oraQueryGetTableData = "SELECT * FROM MY_TABLE";

  OracleCommand oraCommandGetTableData = new OracleCommand(oraQueryGetTableData, oraConnection);

  OracleDataReader oraReaderTableData = oraCommandGetTableData.ExecuteReader();

  DataTable dataTable = new DataTable();
  dataTable.Load(oraReaderTableData);

  // Exception might occur here
  dataTable.WriteXml(writer, true);  

What is the problem here or how can I fix this?

like image 669
Nime Cloud Avatar asked Feb 10 '16 11:02

Nime Cloud


1 Answers

As the exception says - the table does not have it's TableName property set. So you just need to set it.

DataTable dataTable = new DataTable { TableName = "MyTableName"};
dataTable.Load(oraReaderTableData);
....
like image 52
Jens Meinecke Avatar answered Oct 06 '22 01:10

Jens Meinecke