Solved

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

Posted on 2010-09-17
17
1,314 Views
Last Modified: 2012-05-10
Hi  Experts

I have a treeview which looks like this

parent
      child1
      child2
when i click on child2, it takes me to the page i need to see. Since the node collaspses i have to click on it to re-open it but instead i recieve the above error.

i have read this but i can't figure it out.

please help

http://codebetter.com/blogs/raymond.lewallen/archive/2005/06/23/65033.aspx


#region PopulateSubLevel code
    private void PopulateSubLevel(int PARENTID, TreeNode parentNode)
    {
        string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
        OracleConnection Connection = new OracleConnection(connString);
        OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);
        objCommand.Parameters.Add(":PARENTID", SqlDbType.Int).Value = PARENTID;>>>>errors here
        OracleDataAdapter da = new OracleDataAdapter(objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(dt, parentNode.ChildNodes);
    }
    #endregion

Open in new window

0
Comment
Question by:SirReadAlot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 5
17 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33699680
If you get into this procedure, is the parentid variable filled or is it showing null ?
0
 

Author Comment

by:SirReadAlot
ID: 33699752
shows 4  on breakpoint
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33699768
I see it now, you need to add a new parameter


OracleParameter p_parentID = New OracleParameter("PARENTID", SqlDbType.Int)
p_parentID .Direction = ParameterDirection.Input;
p_parentID .Value = PARENTID
objCommand.Parameters.Add(parentID)


       OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);

OracleParameter p_parentID = New OracleParameter("PARENTID", SqlDbType.Int);
p_parentID.Direction = ParameterDirection.Input;
p_parentID.Value = PARENTID;
objCommand.Parameters.Add(parentID);

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 5

Expert Comment

by:kosturdur
ID: 33699794
Try using Oracle Data Type like OracleType.Int32;
Example;
string sql = "SELECT * FROM Customers WHERE CustomerId = :CustomerId";
OracleCommand command = new OracleCommand(sql);
command.Parameters.Add(new OracleParameter(":CustomerId", OracleType.Int32));
command.Parameters[":CustomerId"].Value = 1;
0
 

Author Comment

by:SirReadAlot
ID: 33699804
hi dhaest

i still have the same error on a second click on the item
==================

private void PopulateSubLevel(int PARENTID, TreeNode parentNode)
    {
        string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
        OracleConnection Connection = new OracleConnection(connString);
        OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);
        objCommand.Parameters.Add(":PARENTID", SqlDbType.Int).Value = PARENTID;=======================herte
        objCommand.Parameters.Add(PARENTID);
        OracleDataAdapter da = new OracleDataAdapter(objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(dt, parentNode.ChildNodes);
    }
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33699806
Like I already said, you need to add a oracleParameter.

Replace this line
objCommand.Parameters.Add(":PARENTID", SqlDbType.Int).Value = PARENTID

with
command.Parameters.Add(new OracleParameter("PARENTID", SqlDbType.Int));
command.Parameters["PARENTID"].Value = PARENTID;
0
 
LVL 5

Expert Comment

by:kosturdur
ID: 33699831
Hi SirReadALot,

Did you try using Oracle Data Type like OracleType.Int32;
Example;
string sql = "SELECT * FROM Customers WHERE CustomerId = :CustomerId";
OracleCommand command = new OracleCommand(sql);
command.Parameters.Add(new OracleParameter(":CustomerId", OracleType.Int32));
command.Parameters[":CustomerId"].Value = 1;

So use;
command.Parameters.Add(new OracleParameter("PARENTID", OracleType.Int32));
command.Parameters[":PARENTID"].Value = PARENTID;
0
 
LVL 5

Expert Comment

by:kosturdur
ID: 33700325
Did you solve your problem?
0
 

Author Comment

by:SirReadAlot
ID: 33700411
sorry for the delay.....

i haven't solved the problem, its still occuring

it even failed with Oracle Data Type like OracleType.Int32;

string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
        OracleConnection Connection = new OracleConnection(connString);
        OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);
        objCommand.Parameters.Add(new OracleParameter("PARENTID", SqlDbType.Int));
        objCommand.Parameters["PARENTID"].Value = PARENTID;
        OracleDataAdapter da = new OracleDataAdapter(objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(dt, parentNode.ChildNodes);
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33700443
What error do you get ?
try
{
string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
        OracleConnection Connection = new OracleConnection(connString);
        OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);
        objCommand.Parameters.Add(new OracleParameter("PARENTID", SqlDbType.Int));
        objCommand.Parameters["PARENTID"].Value = PARENTID;
        OracleDataAdapter da = new OracleDataAdapter(objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(dt, parentNode.ChildNodes);
}
Catch (Exception e)
{
    Messagebox.Show(e.ToString());
}

Open in new window

0
 

Author Comment

by:SirReadAlot
ID: 33700505
?e
{System.NullReferenceException: Object reference not set to an instance of an object.
   at Oracle.DataAccess.Client.OracleParameter.Initialize(ParameterDirection direction, Boolean isNullable, OracleDbType oraDbType, String paramName, Byte precision, Byte scale, Int32 size, String srcColumn, DataRowVersion srcVersion, Object obj)
   at Oracle.DataAccess.Client.OracleParameter..ctor(String parameterName, Object obj)
   at GradeEntry_Modules.PopulateSubLevel(Int32 PARENTID, TreeNode parentNode) in c:\Visual Studio 2008\WebSites\he_wizard\GradeEntry\Modules.aspx.cs:line 167}
    [System.NullReferenceException]: {System.NullReferenceException: Object reference not set to an instance of an object.
   at Oracle.DataAccess.Client.OracleParameter.Initialize(ParameterDirection direction, Boolean isNullable, OracleDbType oraDbType, String paramName, Byte precision, Byte scale, Int32 size, String srcColumn, DataRowVersion srcVersion, Object obj)
   at Oracle.DataAccess.Client.OracleParameter..ctor(String parameterName, Object obj)
   at GradeEntry_Modules.PopulateSubLevel(Int32 PARENTID, TreeNode parentNode) in c:\Visual Studio 2008\WebSites\he_wizard\GradeEntry\Modules.aspx.cs:line 167}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "Oracle.DataAccess"
    StackTrace: "   at Oracle.DataAccess.Client.OracleParameter.Initialize(ParameterDirection direction, Boolean isNullable, OracleDbType oraDbType, String paramName, Byte precision, Byte scale, Int32 size, String srcColumn, DataRowVersion srcVersion, Object obj)\r\n   at Oracle.DataAccess.Client.OracleParameter..ctor(String parameterName, Object obj)\r\n   at GradeEntry_Modules.PopulateSubLevel(Int32 PARENTID, TreeNode parentNode) in c:\\Visual Studio 2008\\WebSites\\he_wizard\\GradeEntry\\Modules.aspx.cs:line 167"
    TargetSite: {Void Initialize(System.Data.ParameterDirection, Boolean, Oracle.DataAccess.Client.OracleDbType, System.String, Byte, Byte, Int32, System.String, System.Data.DataRowVersion, System.Object)}
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33700539
Let's try to narrow it down.

Can you try this

string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
        OracleConnection Connection = new OracleConnection(connString);
        OracleCommand objCommand = new OracleCommand(@"select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);


OracleParameter p_parentID = New OracleParameter("PARENTID", SqlDbType.Int)
p_parentID .Direction = ParameterDirection.Input;
p_parentID .Value = PARENTID
objCommand.Parameters.Add(parentID)


Just to see if you can create the oracleParameter or that there is something else ...
0
 
LVL 5

Accepted Solution

by:
kosturdur earned 500 total points
ID: 33700548
Could you try this;
string connString = ConfigurationManager.ConnectionStrings["HE_WIZARD"].ConnectionString;
OracleConnection Connection = new OracleConnection(connString);
OracleCommand objCommand = new OracleCommand("select ID,TITLE,REPORT,(select count(*) FROM HE_GRADE_ENTRY WHERE PARENTID=sc.ID) childnodecount FROM HE_GRADE_ENTRY sc where PARENTID= :PARENTID", Connection);
objCommand.Parameters.Add(new OracleParameter(":PARENTID",OracleType.Int32));
objCommand.Parameters[":PARENTID"].Value = PARENTID;
OracleDataAdapter da = new OracleDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);

Open in new window

0
 

Author Comment

by:SirReadAlot
ID: 33700549
fire alarm...c u soon
0
 

Author Comment

by:SirReadAlot
ID: 33700613
ok... will try ur code now

0
 

Author Comment

by:SirReadAlot
ID: 33700624
works fine..

thanks
0
 
LVL 5

Expert Comment

by:kosturdur
ID: 33700892
Opps take care :)
Opps your welcome
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question