This is one that has been driving me crazy for a few weeks. I finally decided to get to the root of it:
I have an ODS control that sits between a GridView and a data class that returns a DataTable. I manipulate the datatable in the ObjectDataSource_Selected event. If my data class throws an exception, I never see it, however I receive a "System.NullReferenceException: Object reference not set to an instance of an object." when attempting to access the Rows.Count property within the ODS Selected event:
protected void ObjectDataSourceMain_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
DataTable dataTable = (DataTable)e.ReturnValue;
if (dataTable.Rows.Count == 0) // <- Exception!
// ...
}
The solution involves checking the e.Exception property and throwing the exception when e.Exception is not null. In this case I receive the offending "System.Data.SqlClient.SqlException: Invalid column name 'CcontentID'." exception:
if (e.Exception != null)
throw e.Exception;
if (dataTable.Rows.Count == 0)
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Andrew Robinson
E-mail