I want to list all tables and their row count, in an MS Access database, in a grid view. I am using a query as follows:
SELECT MSysObjects.Name, CLng(DCount('*',[name])) AS RecordCount FROM MSysObjects WHERE (((MSysObjects.Type)=1) AND (MSysObjects.Name NOT LIKE 'MSys*')) ORDER BY MSysObjects.Name;
In MS Access Query pane this works just fine. But when I run the query via an OleDbCommand object in .NET, although the query produces a resultset I get a row of data with MSysNavPaneGroupCategories in it. This row always throws an error when i try to :
DataRow row = null;
do
{
row = dt.NewRow();
row["TableName"] = (string)dr["Name"];
row["RecordCount"] = (int)dr["RecordCount"]; // Fails here when dr["Name"]==MSysNavPaneGroupCategories
dt.Rows.Add(row);
} while (dr.Read());
The error message is:
System.InvalidOperationException was unhandled.
The provider could not determine the Int32 value. For example, the row was just created, the default for the Int32 column was not available, and the consumer had not yet set a new Int32 value. Source="System.Data"
So my workaround is to MAKE a TEMP table and read from that instead (or set a default value for the column... which overcomes the error but still includes the rogue table in the result set).
What's going on here? MSysNavPaneGroupCategories shouldn't even have made it into the result set.
Theres not much info on the MSysNavPaneGroupCategories system table.
This url says MSysNavPaneGroupCategories is one of three system tables that
define all the content within the Navigation Pane.
.. in Access 2007.
This Microsoft url says
The Navigation Pane, new in Microsoft Office Access 2007, is a central location from which you can easily view and access all your database objects (database objects: An Access database contains objects such as tables, queries, forms, reports, pages, macros, and modules. An Access project contains objects such as forms, reports, pages, macros, and modules.), run reports, or enter data directly in tables.
... in Access 2007.
Why would this table be showing up in an Access 2K database table listing when its an Access 2007 feature, and why does it show up at all in a query for which it doesn't match the criteria?