日期:2008-07-17  浏览次数:20534 次

using System;
using System.Data;
using System.Data.Common;
using System.Collections;

using System.XML;
using System.XML.XPath;

namespace System.Data.XMLClient
{
    public class XMLDataAdapter : DataAdapter
    {
    // Constructors
    public XMLDataAdapter()
        {
        }

    public XMLDataAdapter(XMLCommand selectCommand)
    {
      _selectCommand = selectCommand;
    }

    public XMLDataAdapter(string selectCommandText)
    {
      _selectCommand = new XMLCommand(selectCommandText, new XMLConnection());
    }

    public XMLDataAdapter(string selectCommandText, XMLConnection selectConnection)
    {
      _selectCommand = new XMLCommand(selectCommandText, selectConnection);
    }

    ////////////////////
    // Properties
    ////////////////////

    public XMLCommand SelectCommand
    {
      get { return _selectCommand;  }
      set { _selectCommand = value; }
    }

    ////////////////////
    // DataAdapter
    ////////////////////

    public override int Fill (DataSet dataSet)
    {
      // Empty the DataSet
      ClearDataSet(dataSet);

      // Fill the DataSet
      dataSet.ReadXML(GetXMLReader());

      // Count the Rows
      int returnVal = 0;
      foreach (DataTable tbl in dataSet.Tables)
      {
        returnVal += tbl.Rows.Count;
      }
      return returnVal;
    }

    public override DataTable[] FillSchema( DataSet dataSet, SchemaType schemaType )
    {
      // Empty the DataSet
      ClearDataSet(dataSet);

      // Fill the DataSet's Schema
      dataSet.ReadXMLSchema(GetXMLReader());

      // Make copy of all the Tables (schema only)
      IEnumerator tableEnum = dataSet.Tables.GetEnumerator();
      DataTable[] aTables = new DataTable[dataSet.Tables.Count];
      for (int x = 0; x < dataSet.Tables.Count; ++x)
      {
        aTables[x] = dataSet.Tables[x];
      }
      return aTables;
    }

    public override IDataParameter[] GetFillParameter