Results 1 to 4 of 4

Thread: Object reference not set to an instance of an object

  1. #1
    Join Date
    Aug 2009
    Posts
    58

    Object reference not set to an instance of an object

    Code:
    int x=0;
    foreach(DataGridViewRow r1 in this.DataGridView1.Rows)
    {
    if((bool)DataGridView.["CheckBox1", i].value)
    {
    //my_code_goes_here
    }
    x++;
    }
    In the above code, I am getting the error message as "Object reference not set to an instance of an object". I am not above to rectify the problem. Can you help me out to get rid of this error message?

  2. #2
    Join Date
    May 2008
    Posts
    685

    Re: Object reference not set to an instance of an object

    To resolve this problem, register the Adodb.dll file in the global assembly cache (GAC). On a computer where only the .NET Framework is installed, the file Gacutil.exe does not exist. Either obtain the gacutil file by installing Microsoft .NET Framework SDK, or create a Visual Studio.NET setup project that uses the installer to install the correct components.

    To register Adodb.dll in the GAC, follow these steps:

    1. Click Start and then click Run.
    2. In the Run dialog box, type the following command, and then click OK:
    C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\gacutil /i C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Object reference not set to an instance of an object

    Several possibilities may lead to this kind of error messages, some of which are over here:

    - You have not assigned anything to the variable.
    - You have not created an instance of the value assigned to the variable.
    - You initialized the variable to NOTHING or NULL, or you called a function that does the same thing.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Object reference not set to an instance of an object

    This error message indicated that you are trying to access a member of a class without any instance object. So make sure that you are having some instance of the class to access its member variables or functions. And for your information, your code will run only once because there is no iteration in your FOREACH condition. If you are incrementing something then it should be used in your conditional statement.

Similar Threads

  1. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  2. Assigning a reference to an object
    By Gillian Anderson in forum Software Development
    Replies: 5
    Last Post: 26-03-2010, 02:05 PM
  3. Differentiation between C++ object and instance
    By Ram Bharose in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 01:40 PM
  4. Fix Error 0x80040706 object reference not set
    By Maximilian5 in forum Windows Software
    Replies: 3
    Last Post: 25-05-2009, 02:15 PM
  5. Replies: 5
    Last Post: 02-03-2009, 09:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,509,068.10213 seconds with 17 queries