无法序列化数据表.未设置数据表名称 [英] Cannot serialize the DataTable. DataTable name is not set
问题描述
我需要将所有数据表导出到单个XML文件,并且如果有巨大的表,由于System.OutOfMemoryException,我无法一次导出所有行.所以我试图导出N行.但是,如果我在查询中使用分页语法,则WriteXml会引发异常.
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.
我已经在LINQPad中测试了两个查询,都可以.
I've tested both queries in LINQPad, they are ok.
System.InvalidOperationException:无法序列化DataTable. 未设置数据表名称.
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?
推荐答案
作为例外,表没有设置TableName
属性.因此,您只需要设置它即可.
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);
....
这篇关于无法序列化数据表.未设置数据表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!