Object reference not set to an instance of an object error

Object reference not set to an instance of an object error

Post by Kerry McCulloug » Thu, 30 May 2002 03:22:29



Can anyone tell me why I am getting this error?  Below is an example of
my code, along with the error message a stack trace.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 54:             ds = New DataSet()Line 55:             da = New
OleDbDataAdapter("SELECT * FROM TBLPEOPLE", cn)Line 56:
da.Fill(ds)Line 57: Line 58:             '    retstr =
System.Environment.StackTrace.ToString

Source File: C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb
Line: 56

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]   System.Data.Common.IRowset.GetData(IntPtr hRow, IntPtr
hAccessor, IntPtr pData) +0
System.Data.OleDb.OleDbDataReader.GetRowDataFromHandle()
System.Data.OleDb.OleDbDataReader.FindValueBinding(Int32 index)
System.Data.OleDb.OleDbDataReader.PeekValueBinding(Int32 index)
System.Data.OleDb.OleDbDataReader.GetValues(Object[] values)
System.Data.Common.SchemaMapping.LoadDataRow(Boolean clearDataValues,
Boolean acceptChanges)
System.Data.Common.DbDataAdapter.FillLoadDataRow(SchemaMapping mapping)
System.Data.Common.DbDataAdapter.FillFromReader(Object data, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords,
DataColumn parentChapterColumn, Object parentChapterValue)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb:56
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Dim cn As New OleDbConnection()
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim cm As OleDbCommand
Dim rowcount As Integer
Dim retstr As String

cn.ConnectionString = "Provider=OraOLEDB.Oracle;Data
Source=ORA9ITST;User ID=dbo;Password=master;Database=ORA9ITST"
cn.Open()

cm = New OleDbCommand("", cn)
cm.CommandText = "ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY'"
cm.CommandType = CommandType.Text
rowcount = cm.ExecuteNonQuery()
retstr = CStr(rowcount)

'Fill Dataset
ds = New DataSet()
da = New OleDbDataAdapter("SELECT * FROM TBLPEOPLE", cn)
da.Fill(ds)

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Object reference not set to an instance of an object error

Post by Jave » Thu, 30 May 2002 14:23:00


Obviously one of the objects you are using has a value
of 'nothing' - which one? is not readily obvious from
your post.  The best way to catch these is to set a
breakpoint near that part of the code, and then run your
mouse pointer over the objects in the vicinity.  You are
bound to find one that comes as 'nothing'.

Quote:>-----Original Message-----
>Can anyone tell me why I am getting this error?  Below
is an example of
>my code, along with the error message a stack trace.

>Object reference not set to an instance of an object.
>Description: An unhandled exception occurred during the
execution of the
>current web request. Please review the stack trace for
more information
>about the error and where it originated in the code.

>Exception Details: System.NullReferenceException: Object
reference not
>set to an instance of an object.

>Source Error:
>Line 54:             ds = New DataSet()Line

55:             da = New

- Show quoted text -

Quote:>OleDbDataAdapter("SELECT * FROM TBLPEOPLE", cn)Line 56:
>da.Fill(ds)Line 57: Line 58:             '    retstr =
>System.Environment.StackTrace.ToString

>Source File: C:\Inetpub\wwwroot\WebApplication1
\WebForm1.aspx.vb
>Line: 56

>Stack Trace:
>[NullReferenceException: Object reference not set to an
instance of an
>object.]   System.Data.Common.IRowset.GetData(IntPtr
hRow, IntPtr
>hAccessor, IntPtr pData) +0
>System.Data.OleDb.OleDbDataReader.GetRowDataFromHandle()
>System.Data.OleDb.OleDbDataReader.FindValueBinding(Int32
index)
>System.Data.OleDb.OleDbDataReader.PeekValueBinding(Int32
index)
>System.Data.OleDb.OleDbDataReader.GetValues(Object[]
values)
>System.Data.Common.SchemaMapping.LoadDataRow(Boolean
clearDataValues,
>Boolean acceptChanges)
>System.Data.Common.DbDataAdapter.FillLoadDataRow

(SchemaMapping mapping)
Quote:>System.Data.Common.DbDataAdapter.FillFromReader(Object
data, String
>srcTable, IDataReader dataReader, Int32 startRecord,
Int32 maxRecords,
>DataColumn parentChapterColumn, Object
parentChapterValue)
>System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,
String srcTable,
>IDataReader dataReader, Int32 startRecord, Int32
maxRecords)
>System.Data.Common.DbDataAdapter.Fill(Object data, Int32
startRecord,
>Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior
>behavior)   System.Data.Common.DbDataAdapter.Fill

(DataSet dataSet, Int32

- Show quoted text -

Quote:>startRecord, Int32 maxRecords, String srcTable,
IDbCommand command,
>CommandBehavior behavior)
>System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
>WebApplication1.WebForm1.Page_Load(Object sender,
EventArgs e) in
>C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb:56
>System.Web.UI.Control.OnLoad(EventArgs e)
>System.Web.UI.Control.LoadRecursive()
>System.Web.UI.Page.ProcessRequestMain()

>Dim cn As New OleDbConnection()
>Dim ds As DataSet
>Dim da As OleDbDataAdapter
>Dim cm As OleDbCommand
>Dim rowcount As Integer
>Dim retstr As String

>cn.ConnectionString = "Provider=OraOLEDB.Oracle;Data
>Source=ORA9ITST;User

ID=dbo;Password=master;Database=ORA9ITST"

- Show quoted text -

Quote:>cn.Open()

>cm = New OleDbCommand("", cn)
>cm.CommandText = "ALTER SESSION SET NLS_DATE_FORMAT
= 'MM/DD/YYYY'"
>cm.CommandType = CommandType.Text
>rowcount = cm.ExecuteNonQuery()
>retstr = CStr(rowcount)

>'Fill Dataset
>ds = New DataSet()
>da = New OleDbDataAdapter("SELECT * FROM TBLPEOPLE", cn)
>da.Fill(ds)

>Thanks

>*** Sent via Developersdex http://www.developersdex.com
***
>Don't just participate in USENET...get rewarded for it!
>.