Solved

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

Posted on 2010-09-17
17
1,252 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now