OddiC
asked on
Invalid Cast Exception when trying to set DataGrid DataSource = IDataReader object (why??...)
Here is my code which calls a function that returns an IDataRreader object (I have verified that the IDataReader is populated with the correct data set I wish to use as my DataSource):
dgMyGrid.DataSource = GetIDataReaderDataSource()
Try
dgBillTo.DataBind() 'fails on this line with "Invalid Cast Exception"
Catch ex As Exception
End Try
Can someone tell me why this is occuring and what I can do alternatively to make it work?
Thanks much in advance.
dgMyGrid.DataSource = GetIDataReaderDataSource()
Try
dgBillTo.DataBind() 'fails on this line with "Invalid Cast Exception"
Catch ex As Exception
End Try
Can someone tell me why this is occuring and what I can do alternatively to make it work?
Thanks much in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am working with 1.1
I am not sure how I define the grid column types as they are not being auto-generated and are defined at runtime based on the datasource.
Any thoughts?
I am not sure how I define the grid column types as they are not being auto-generated and are defined at runtime based on the datasource.
Any thoughts?
ASKER
I figured it out. I needed to use DataTable instead of DataReader (my cast on ItemDataBound was not working with DataReader).
This is what was failing because the datasource was datareader:
Dim odr As DataRowView = DirectCast(e.Item.DataItem , DataRowView)
Does anyone know how the above can be accomplished with a DataSource of DataReader?? (just for piece of mind).
Thanks.
This is what was failing because the datasource was datareader:
Dim odr As DataRowView = DirectCast(e.Item.DataItem
Does anyone know how the above can be accomplished with a DataSource of DataReader?? (just for piece of mind).
Thanks.
if you have, then any nulls in the data will cause that error