OleDbDataReader Null REference


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: OleDbDataReader Null REference

  1. #1
    Join Date
    Nov 2005
    Posts
    3

    OleDbDataReader Null REference

    Hai,

    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
    Try
    If Not (objDataReader Is Nothing) Then
    objDataReader.Close()
    End If
    selectCmd = New OleDbCommand(Qry, objCon)
    'objCon is the connection object that is opened in session_OnStart.

    objDataReader = selectCmd.ExecuteReader()
    Return objDataReader
    Catch
    errorTracer()
    End Try
    End Function

    Help in time will be grateful.

    Regards
    sindhuja

  2. #2
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    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
    eg
    if(dr.HasRows)
    {
    then bind data to the grid
    }
    else
    {
    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
    Sri

  3. #3
    Join Date
    Nov 2005
    Posts
    3
    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...

  4. #4
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    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.
    Sri

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  2. need help with xml problem
    By Guillermo Hidalgo in forum XML
    Replies: 2
    Last Post: 05-22-2002, 03:49 AM
  3. Getting a large number of identities
    By Colin McGuigan in forum Database
    Replies: 12
    Last Post: 04-15-2002, 07:43 AM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  5. Multi-row calculations
    By Bob Hines in forum Database
    Replies: 7
    Last Post: 04-27-2000, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center