title: C# datatable column datatype
body: <p>I'm importing data from an excel sheet into a datatable and I'm having a problem/question about the datatypes. When I create the datatable, I add the columns and their datatypes. After this I import the data from excel and this works fine. When I check the datatype of the columns it says what I expect. However, when I try and pass a value to a function I get the message that I'm trying to pass an object type, instead of the datatype I set.</p>
  
  <p>here's my code (it's a simplified dataset):</p>
  
  <pre><code>public void importData(string _file)
      {
          DataTable dtTest = new DataTable();
          dtTest.Columns.Add("a", typeof(Int32));
          dtTest.Columns.Add("b", typeof(Int32));
  
          string connString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data       Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", _file);
          OleDbConnection conn = new OleDbConnection(connString);
  
          conn.Open();
  
          OleDbDataAdapter objAdapter = new OleDbDataAdapter();
  
          string sheetName = "Sheet1";
          string sql = "SELECT * FROM [" + sheetName + "$]";
  
          OleDbCommand objCmdSelect = new OleDbCommand(sql, conn);
          objAdapter.SelectCommand = objCmdSelect;
  
          objAdapter.Fill(dtTest);
          conn.Close();
  
          form.write(dtTest.Rows[0]["a"]);
      }
  </code></pre>
  
  <p>the function 'form.write()' accepts an integer.</p>
  
  <p>when I check the datatype before I try and pass the value to form.write, it says it's Int32.</p>
  
  <pre><code>if (dtTest.Columns[0].DataType == typeof(Int32))
          {
              //this is true
          }
  </code></pre>
  
  <p>what am I doing wrong?</p>