Solved

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

Posted on 2010-09-17
17
1,238 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

10 Experts available now in Live!

Get 1:1 Help Now