Avatar of homeshopper
homeshopper
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Object reference not set to an instance of an object.

I am getting following error: Object reference not set to an instance of an object
strArrayDB33[intDetail] = "AdminDB2";//line 129 Object reference not set to an instance of an object.
Thankyou in advance for any help given.
Full code as per attached snippet.
tempScript0.txt
ASP.NETC#

Avatar of undefined
Last Comment
homeshopper

8/22/2022 - Mon
Nice-Ghaza

Some Thing Wrong because Virus File .install the Antivirus Latest one
ASKER CERTIFIED SOLUTION
Paul Jackson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Easwaran Paramasivam

homeshopper

ASKER
Thankyou for your comments. If I delete following code it works:
strArrayDB33 = (String[])Session["strArrayDB33"];
strArrayDetail33 = (String[])Session["strArrayDetail33"];
strArrayTable33 = (String[])Session["strArrayTable33"];
But, this now creates a new problem.
Elsewhere the elements/index of the array are incremented.
Then when it returns it does display the contents of the selected element of the array.
strArrayDB33 where i is the incremented element.
for example strArrayDB33[3]
But, now elements 0 to 2 are destroyed.
How can I preserve all other contents of the array?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Easwaran Paramasivam

Make sure that you have created array with required size and make sure that you ADDED properly before increment the value.

say for example:

string[] myArr = new string[3];
myArr[0] = "one";
myArr[1] = "two";
myArr[2] = "three";

Open in new window

homeshopper

ASKER
yes, I understand what you say. Code Below:
protected string[] strArrayDB33 = new string[11];
protected string[] strArrayDetail33 = new string[11];
protected string[] strArrayTable33 = new string[11];
    protected void Page_Load(object sender, EventArgs e)
    {
    }
I have the following at the end of the code block:
for (var j = 0; j <= 10; j++)
            {
                Response.Write("(" + Convert.ToChar(j + 65) + ")" + strArrayDetail33[j] + "#&nbsp;&nbsp;Tab:" + "<a href='../scriptFrame/tempScript" + (currentPage).ToString() + ".aspx?db22=" + strArrayDB33[j] + "&dt22=" + strArrayTable33[j] + "&intDetail22=" + j + "&strD22=False" + "&PageID=" + (currentPage).ToString() + " ' title='" + strArrayTable33[j] + "' runat='server'>" + "<font color='#0000FF' size='1'>" + strArrayTable33[j] + "</font>" + "</a>#<br/>");
            }
            //********************************************************
            Session["strArrayDB33"] = strArrayDB33;
            Session["strArrayDetail33"] = strArrayDetail33;
            Session["strArrayTable33"] = strArrayTable33;
            Session["strIntDetail22"] = intstrDetail22;
        }
The following is displayed:
(A)#  Tab:#
(B)#  Tab:#
(C)#  Tab:#
(D)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblLinks#
(E)#  Tab:#
(F)#  Tab:#
(G)#  Tab:#
(H)#  Tab:#
(I)#  Tab:#
(J)#  Tab:#
(K)#  Tab:#
It displays the contents of the array at element [3] (D)
but contents in [0], [1], [2] or (A), (B), (C) are lost.
So that is why I put the following at the beginning of the code block,
to try and preserve all contents. But, then it causes the original error.
Thanks in advance for any help given.
public void BindData0()
    {
        try
        {
            strArrayDB33 = (String[])Session["strArrayDB33"];
            strArrayDetail33 = (String[])Session["strArrayDetail33"];
            strArrayTable33 = (String[])Session["strArrayTable33"];
homeshopper

ASKER
I have now managed to display the following:
(A)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=AdminDB2#  Tab:AdminTable#
(B)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=pubs#  Tab:employee#
(C)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Northwind#  Tab:Customers#
(D)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblFavourites#
(E)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:vw_ModSub_Sorted#
(F)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Northwind#  Tab:Employees#
(G)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblRole#
(H)#  Tab:#
(I)#  Tab:#
(J)#  Tab:#
(K)#  Tab:#
I thought I'll test the Session["strArrayDB33"] for 'Null'
as it was previously suggested. It now all works by adding the following:
public void BindData0()
    {
        try
        {
            if (Session["strArrayDB33"] == null)
            {

            }
            else
            {
                strArrayDB33 = (String[])Session["strArrayDB33"];
                strArrayDetail33 = (String[])Session["strArrayDetail33"];
                strArrayTable33 = (String[])Session["strArrayTable33"];
            }
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.