-
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
-
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
-
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.
Sri
Similar Threads
-
Replies: 4
Last Post: 04-14-2006, 09:09 AM
-
By Guillermo Hidalgo in forum XML
Replies: 2
Last Post: 05-22-2002, 03:49 AM
-
By Colin McGuigan in forum Database
Replies: 12
Last Post: 04-15-2002, 07:43 AM
-
Replies: 1
Last Post: 11-27-2001, 07:53 AM
-
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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|