title: Input array is longer than the number of columns in this table?
body: <p>I keep getting this error all day today and I can't see how it is possible that it is happening? I am making a <code>DataTable</code>,and it has 7 columns , but when trying to add the array to the the table I get the error.</p>
  <p>This is the code;</p>
  <pre><code>    public static void BulkEntityInsert&lt;T&gt;(this T entity, List&lt;T&gt; entities)
      {
          //give array lenght
          string[] columns = new string[7];          
  
          DataTable dataTable = new DataTable();
          try
          {
              int jj = 0;
              DataColumn datecolumn = new DataColumn();
              foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(entity))
              {
                  datecolumn.AllowDBNull = true;
                  datecolumn.ColumnName = prop.Name == &quot;Id&quot; ? &quot;ID&quot; : prop.Name;
                  datecolumn.DataType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                  columns[jj] = prop.Name == &quot;Id&quot; ? &quot;ID&quot; : prop.Name;                    
                  jj++;
              }
  
              foreach (T t in entities)
              {
                  // give the record array the same length as the columns variable
                  object[] record = new object[columns.Length];
                  
                  int j = 0;
                  foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(t))
                  {
                      record[j] = prop.GetValue(t);
                      j++;
                  }
                  // Errror occurs here
                  dataTable.Rows.Add(record);
              }
              // Save data to DB
              SqlBulkCopyInsert(dataTable);
          }
          catch (Exception ex)
          {
              MessageBox.Show(&quot;DataTable was not correctly made&quot;, ex.Message);
          }           
      }
  </code></pre>
  <p>Any help to solve this would be much appreciated.</p>