Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-09-2009
Member
 
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?
Reply With Quote
  #2  
Old 05-09-2009
Member
 
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
Reply With Quote
  #3  
Old 05-09-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #4  
Old 05-09-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Object reference not set to an instance of an object"
Thread Thread Starter Forum Replies Last Post
Getting HP AIO Device object server register class object failed message on my system Donoho Hardware Peripherals 6 06-06-2011 01:34 AM
Assigning a reference to an object Gillian Anderson Software Development 5 26-03-2010 02:05 PM
Differentiation between C++ object and instance Ram Bharose Software Development 4 06-02-2010 01:40 PM
Fix Error 0x80040706 object reference not set Maximilian5 Windows Software 3 25-05-2009 02:15 PM
What is the difference between an object and an instance in java? Lalit5 Software Development 5 02-03-2009 09:00 PM


All times are GMT +5.5. The time now is 03:58 AM.