title: How to return a datatable from a database table, not using adapter.fill
body: <p>I wish to return a Datatable not using the adapter.fill technique.</p>
  
  <pre><code>    internal DataTable ConnectedSelect(string TableName, string[] Cols, string Condition)
      {
          DataTable dt = new DataTable();
          using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
          {
              con.Open();
              using (SqlCommand cmd = new SqlCommand(GenerateSelectStatment(TableName, Cols, Condition),con))
              {
                  SqlDataReader rdr = cmd.ExecuteReader();
                  object[] temp = new object[rdr.FieldCount];
                  while (rdr.Read())
                  {
                     rdr.GetValues(temp);
                     dt.Rows.Add(temp);
                  }
              }
          }
          return dt;
      }
      }
  </code></pre>
  
  <p>problem is i get Input array is longer than number of col in this table.
  table has 4 columns 
  What could be the problem?
  the rows.add should be adding a row with 4 elements which is the same as input.</p>