title: How do I convert an object containing an Oracle Date to a DateTime?
body: <p>The method below uses OracleDataReader.GetValues() to stuff SQL results into an array of objects.</p>
  
  <p>From that array, calling methods can convert, e.g. numbers to longs with <code>Convert.ToInt64(row["FOO_COLUMN"])</code>, but cannot reliably get a date. I cannot use <code>TO_CHAR(some_date_format)</code> because the method must work with <code>SELECT * FROM ...</code>.</p>
  
  <p>I've tried checking each column to see if it is an OracleDate via the three lines of commented code below. The contents of the if() statement in question may be incorrect, but it doesn't matter because the if() condition is never met.</p>
  
  <p>I've searched but was surprised that either my search skills need some work or that no one has ever asked this question, probably the former.</p>
  
  <pre><code>    public IDictionary&lt;int, IDictionary&lt;string, object&gt;&gt;
      dbQuery(string sql, Dictionary&lt;string, object&gt; parameters = null, string connectionString = null) {
          var dbResults = new Dictionary&lt;int, IDictionary&lt;string, Object&gt;&gt;();
          if(connectionString == null) connectionString = this.defaultQueryConnectionString;
          using(var con = new OracleConnection(connectionString)) {
              using(var cmd = new OracleCommand(sql, con)) {
                  cmd.BindByName = true;
  
                  if(parameters != null) {
                      OracleParameter[] parameterArray = new OracleParameter[parameters.Count];
                      int parameterIndex = 0;
                      foreach(var parameter in parameters) {
                          parameterArray[parameterIndex] = new OracleParameter(parameter.Key, parameter.Value);
                          ++parameterIndex;
                      }
                      cmd.Parameters.AddRange(parameterArray);
                  }
  
                  con.Open();
                  var reader = cmd.ExecuteReader();
  
                  int columnCount = reader.FieldCount;
                  object[] columns = new object[columnCount];
                  int rowNum = 0;
                  while(reader.Read()) {
                      reader.GetValues(columns);
                      var colval = new Dictionary&lt;string, object&gt;();
                      for(int columnIndex = 0; columnIndex &lt; columnCount; ++columnIndex) {
                          //if(columns[columnIndex] is OracleDate) {
                          //    columns[columnIndex] = Convert.ToDateTime(columns[columnIndex]);
                          //}
                          string colName = reader.GetName(columnIndex).ToUpperInvariant();
                          colval.Add(colName.ToUpperInvariant(), columns[columnIndex]);
                      }
                      dbResults.Add(rowNum, colval);
                      ++rowNum;
                  }
              }
          }
          return dbResults;
      }
  </code></pre>