© 2004 Microsoft Corporation. All rights reserved.
Figure 2 IDbConnection Interface
public interface IDbConnection
  IDbTransaction BeginTransaction(IsolationLevel iso)
  IDbTransaction BeginTransaction()
  bool ChangeDatabase(string newdb)
  void Close()
  IDbCommand CreateCommand()
  void Open()

// properties
 string ConnectionString  // get, set
 int ConnectionTimeout    // get, set
 string Database          // get, set
 ConnectionState State    // get
Figure 3 ConnectionState Enumeration

Member Name
The object is broken. This can occur only after the connection has been opened. A connection in this state may be closed and then reopened
The object is closed
The object is connecting
The object is executing a command
Data is being retrieved
The object is open
Figure 4 IDbCommand Interface
public interface IDbCommand
public void Cancel()
public IDataParameter CreateParameter()
public int ExecuteNonQuery()
public IDataReader ExecuteReader()
public IDataReader ExecuteReader(CommandBehavior b)
public object ExecuteScalar()

public string CommandText                  // get, set
public int CommandTimeout                  // get, set
public CommandType CommandType             // get, set
public IDbConnection Connection            // get, set
public IDataParameterCollection Parameters // get
public IDbTransaction Transaction          // get, set
public UpdateRowSource UpdatedRowSource    // get, set
Figure 5 CommandBehavior Enumeration

Member Name
When the command is executed, the associated Connection object is closed when the associated DataReader object is closed
The query returns column and primary key information
The query returns column information only and does not affect the database state
The results of the query are read sequentially to the column level
The query returns a single result. Execution of the query may affect the database state
The query is expected to return a single row. Execution of the query may affect the database state
Figure 6 ExecuteReader
public IDataReader ExecuteReader(CommandBehavior b)
    Debug.WriteLine("MDirCommand.ExecuteReader(b)", "MDirCommand");

    // must have a valid and open connection
    if (_Connection == null || _Connection.State != ConnectionState.Open)
        throw new InvalidOperationException("Connection must be valid and

    if ((b & CommandBehavior.KeyInfo) > 0)
        Debug.WriteLine("Behavior includes KeyInfo");

    if ((b & CommandBehavior.SchemaOnly) > 0)
        Debug.WriteLine("Behavior includes SchemaOnly");

    // only implement CloseConnection and "all other"
    if ((b & CommandBehavior.CloseConnection) > 0)
        Debug.WriteLine("Behavior includes CloseConnection");
        MDirDataReader reader = new MDirDataReader(_CommandText,
        return reader;
        MDirDataReader reader = new MDirDataReader(_CommandText);
        return reader;
Figure 7 IDataReader and IDataRecord
public interface IDataReader
// IDataReader methods
public DataTable GetSchemaTable()
public void Close()
public bool NextResult()
public bool Read()

// IDataReader properties
public int Depth
public bool IsClosed
public int RecordsAffected

public interface IDataRecord
// IDataRecord methods
public bool GetBoolean(int i)
public byte GetByte(int i)
public int GetBytes(int i, int fieldoffset, byte[] buffer,
       int length, int bufferoffset)
public char GetChar(int i)
public int GetChars(int i, int fieldoffset, char[] buffer,
       int length, int bufferoffset)
public IDataReader GetData(int i)
public string GetDataTypeName(int i)
public DateTime GetDateTime(int i)
public decimal GetDecimal(int i)
public double GetDouble(int i)
public Type GetFieldType(int i)
public float GetFloat(int i)
public Guid GetGuid(int i)
public short GetInt16(int i)
public int GetInt32(int i)
public long GetInt64(int i)
public string GetName(int i)
public int GetOrdinal(string name)
public string GetString(int i)
public object GetValue(int i)
public bool IsDBNull(int i)

// IDataRecord properties
public int FieldCount
public object this[string name]
public object this[int i]
Figure 8 MDirDataReader Implementation
// IDataReader.Read()
public bool Read()
    Debug.WriteLine("MDirDataReader.Read", "MDirDataReader");
    if (_ie != null)
        bool notEOF = _ie.MoveNext();
        if (notEOF == true)
            if (_fsi[_CurrentRow] is FileInfo)
                FileInfo f = (FileInfo)_fsi[_CurrentRow];
                _cols[0] = f.Name;
                _cols[1] = f.Length.ToString();
                _cols[2] = "File";
                _cols[3] = f.CreationTime.ToString();
                DirectoryInfo d = (DirectoryInfo)_fsi[_CurrentRow];
                _cols[0] = d.Name;
                _cols[1] = "0";
                _cols[2] = "Directory";
                _cols[3] = d.CreationTime.ToString();
        return notEOF;

    return false;
}// MDirDataReader
// Implementation
// used by MDirCommand.Execute and MDirCommand.ExecuteReader

 * We keep track of the connection to implement the
 * CommandBehavior.CloseConnection flag. null means
 * normal behavior (don't automatically close)
private   IDbConnection _Connection = null;

internal  DirectoryInfo _dir;
internal  FileSystemInfo[] _fsi;
internal  int _CurrentRow;
internal  IEnumerator _ie;

internal  String[] _names = {"Name", "Size", "Type", "CreationDate" };
internal  Type[] _types = {typeof(String), typeof(long), typeof(String),
internal  object[] _cols = new object[4];

// maximum size in bytes
internal  Int32[] _sizes = { 1024, 8, 9, 8 };internal void GetDirectory(String command)
    _dir = new DirectoryInfo(command);
    _fsi = _dir.GetFileSystemInfos();

    _RecordsAffected = _fsi.Length;

    _CurrentRow = -1;
    _ie = _fsi.GetEnumerator();
    _isClosed = false;
Page view tracker