You are using
column.ColumnName
as an index, but that may not work if the value is not a string. You are better using an index value and testing for null on each name. Something like:
for (int index = 0; ; ++index)
{
string columnName = HeaderColumns.Rows[0][index].Value.ToString();
if (string.IsNullOrEmpty(columnName))
break;
}
[edit]
This is what I have used in the past to capture information via OLEDB:
OleDbCommand command = new OleDbCommand(string.Format("Select * From [{0}]", tableName), dbConnection);
OleDbDataReader reader = command.ExecuteReader();
while (dataGridView.RowCount > 1)
{
dataGridView.Rows.RemoveAt(0);
}
if (reader.HasRows)
{
dataGridView.ColumnCount = reader.FieldCount;
for (int row = 0; reader.Read(); ++row)
{
dataGridView.Rows.Add();
for (int column = 0; column < reader.FieldCount; ++column)
{
dataGridView.Columns[column].HeaderText = reader.GetName(column);
Type columnType = reader.GetFieldType(column);
dataGridView[column, row].Value = reader.GetValue(column);
}
}
}
[/edit]