4
protected override DataTable internalExecuteTable(string SQL)
{
    DbDataReader reader = ExecuteReader(SQL);
    DataTable dt = new DataTable();
    dt.Load(reader);
    reader.Close();
    return dt;
}

“internalExecuteTable”带有下划线,并引发“System.Xml”未引用的错误,我应该添加“System.Xml”引用。但为什么?

我使用上面的代码从 SQLite 数据库(System.Data.SQLite 包装器)中读取

4

2 回答 2

10

您正在System.Xml间接使用。DataTable依赖于程序集中定义的类System.Xml。如果您查看该类的文档,或者如果您只是在 IDE 中探索它,您会注意到它包含许多用于读取和写入 XML 的方法,例如。

通过使用System.Data.DataTable,您还需要参考System.Xml

于 2013-03-07T19:21:07.460 回答
0

DataTable is according to MSDN declared as

[SerializableAttribute]
public class DataTable 
     : MarshalByValueComponent,
       IListSource,
       ISupportInitializeNotification,
       ISupportInitialize,
       ISerializable,
       IXmlSerializable

IXmlSerializable declares Methods that use XmlReader, XmlWriter and XmlSchema for either in- or output, all of them declared respectively defined in System.Xml.dll.

If you dive into the code (using the official sources or IL/Decompiler) you may notice an attribute usage:

[XmlSchemaProvider("GetDataTableSchema")]
//...
public class DataTable : //...

Unfortunately the MSDN guys didn't include that reference to System.Xml explicitly in the remarks section - maybe because the usual project templates include it anyways.

于 2013-06-05T12:14:36.737 回答