Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-17
17
Medium Priority
?
1,390 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

885 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