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
Solved

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

Posted on 2010-09-17
17
1,277 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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