I have a base form class that contains a method that returns a DataTable:
protected DataTable GetTableData(string sql, OracleConnection connection)
{
DataTable table = null;
OracleDataAdapter adapter = null;
try
{
table = new DataTable();
adapter = new OracleDataAdapter(sql, connection);
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
}
catch (Exception e)
{
MessageBox.Show("An error occurred while trying to process your request:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (null != adapter)
{
adapter.Dispose();
}
}
return table;
}
Another window is a subclass of it, and invokes it as follows:
private void LoadViewData(OracleConnection connection)
{
DataTable table = null;
try
{
var sql = "SELECT * FROM " + this.ObjectName;
table = GetTableData(sql, connection);
this.resultBindingSource.DataSource = table;
}
catch (Exception e)
{
MessageBox.Show("An error occurred while trying to process your request:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.sqlEditor.Focus();
}
}
resultBindingSource
is a System.Windows.Forms.BindingSource
. It is set as the DataSource
property of a System.Windows.Forms.DataGridView
. (The expression, this.ObjectName
, evaluates to the name of a table or view in the database.)
When I run through the code in the debugger, I can see that the SQL executes just fine. I can see that the DataTable
contains data. I can see that the DataGridView
control is properly bound to the data source, and that I can see the data in the data table through its DataSource
property. However, no data is displayed in the control itself. There are no row or column headers, and no data is displayed whatsoever.
I have tried everything I can think of to pin down the cause of this problem. This code works exactly as shown on another form. I tried deleting the controls in question and recreating them, to no avail. I consulted the articles on MSDN on how to properly databind to a DataGridView
control. I tried it with and without an OracleCommandBuilder
(which doesn't seem necessary to me, since this is a read-only view of the data).
I'm frankly out of ideas. It's likely something fairly obvious that I've overlooked. I know that databinding works, because I've done it before with great success.
Any pointers in the right direction would be greatly appreciated.