OleDbDataReader Null REference
I am Getting some query Result in a OLEDBDataReader. In one case I am using .read method, and in another case I am using that Reader as DataSource of a DataGrid,and do DataBind.
It giving expected result some time,and some other times,it is showing Error,Null Refernce,Object Reference not set to instance of a object.If refreshed again and again, It is showing the result.
What is the problem,How to overcome this?
Here is the code that populates the objDataReder.
Public Shared Function ShowResult(ByVal Qry As String) As Object
If Not (objDataReader Is Nothing) Then
selectCmd = New OleDbCommand(Qry, objCon)
'objCon is the connection object that is opened in session_OnStart.
objDataReader = selectCmd.ExecuteReader()
Help in time will be grateful.
When you use the data reader to bind data on to a grid
Always check the datareader.hasrows method before you bind the data to the grid
then bind data to the grid
display an empty grid / no rows result message
Also beware of nulls in your column use the Isnull function in your stored procedure to handle
I am using ASP.net and in that there is now property like HasRows for DataReader.
And the thing is, for the same set of result I am getting the correct display. Only at times (but frequently) It shows the NullReferenceException. Is there anything related to the DataBase connectivity.Will there be any queue in getting the select command being executed.
Pl give me reply if any idea...
No this is not anything to do with database connectivity ....
Do you bind the datareader directly to the grid?
Secondly is this datareader executed on post back and then loaded based on a user selection? Is it on the postback
Lastly post the code of the binding that happens with the grid on the webform.
Last Post: 04-14-2006, 09:09 AM
By Guillermo Hidalgo in forum XML
Last Post: 05-22-2002, 03:49 AM
By Colin McGuigan in forum Database
Last Post: 04-15-2002, 07:43 AM
Last Post: 11-27-2001, 06:53 AM
By Bob Hines in forum Database
Last Post: 04-27-2000, 11:14 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center