none
Object reference not set to an instance of an object

    Question

  • I get this error in an alert message ("Object reference not set to an instance of an object") when i tried to bind data to my grid view using configure data source window. The rest of the process are working fine. What could be the problem. can any one help me.
    Thursday, March 15, 2007 6:45 AM

Answers

  • I was experiencing the same problem, but seem to have found a solution to this issue:

     

    I was looking at the "Data Sources" toolbox window in my project and noticed there was one data source listed with a "warning" icon (yellow triangle with "!") super-imposed.  This item appeared at the very top of the tree, outside of the project's namespace node.  Apparently I had started to create an Object data source on one of my classes and cancelled it or had an error (don't remember, because I wasn't using that DS). 

     

    Next I opened the "Properties > Data Sources" under Solution Explorer and saw that data source listed there.  I deleted that erroneous data source and left all the other ones alone.  After deleting, everything worked just fine.  Since I hadn't been using that DS, I was lucky not to have been impacted by the delete.

     

    I suspect this error happens when one of the Data Sources in the project is corrupted or otherwise broken, and when VS2005 tries to list that object in the wizards or designers it bombs out.  So if you are getting this error, it's probably because one of your data source project files is corrupted.  Find out which one by looking at the Data Source explorer (on the menu "Data > Show Data Sources") and see if one is listed with a warning icon.  If so, go to Solution Explorer, open the "Properties > Data Sources" folder and delete the ".datasource" file representing the bad DS.

     

    Well I hope this helps some other poor soul out there - good luck!

    Friday, July 13, 2007 5:33 PM

All replies

  • This mean your are using a variable that has not been initialized, that is = to null or nothing. Can you show the part of the code that is doing this ?
    • Proposed as answer by Tanyo Ivanov Wednesday, January 23, 2013 8:31 AM
    Thursday, March 15, 2007 1:57 PM
  •           this error is caused when i tried to bind data in grid view in visual studio 2005. the procedure which i followed are as follows, first i have selected choose data sourse in the grid view task and then i selected new data source. then in the data source configuration wizard i have selected database and moved further. then i have clicked the new connection button and entered all the details and clicked test connection, i get the message 'test connection succeeded' after that when i click ok in the add connection page i get the error 'Object reference not set to an instance of an object error'.

             please help me in correcting this error.

    thanks & regards

    karthi

    Friday, March 16, 2007 5:24 AM
  • Hi,

         First thing u can try is use debugging, so that u can know where the error has occured.

         next thing is use exception handling for creating connection, command etc... u have to check at each level whether object is created or not.

    Cheers,

    Pradeep

    Friday, March 16, 2007 6:37 AM
  • hi pradeep,

       i think debugging and exception handling can only help me when i am using code behind coding, if i am not wrong. i am using the built in feature of binding data. can u help me with this.

    Friday, March 16, 2007 7:00 AM
  • HEllO ALL,

    Reply me for d same!!!!!!!!

    I m also getting this error that object reff is not set 2 an instance..as i m uploading file n that file will get stored in DATA folder which is created in that application.........

    Plz tell me hw 2 resolve that error...in c#.net 1.1

    Thursday, March 22, 2007 6:49 AM
  • I have the same problem, I cannot use the designer for databinding anymore!
    I even get a crash when I use the smarttags for databinding.
    Wednesday, June 06, 2007 9:32 AM
  • Yes, this is an undocumented 'feature', ie VS designer stops working as it ought to. I have found that deleting the object data source and creating a new one sometimes 'fixes' this problem. Only problem is that you then have to redo all of your databinding..which is no joke on a form with lots of controls.

     

    This is another exampler of one of those annoying bugs that seem to pop up just when you're "on a roll", coding brilliantly and don't really want to stop to help Microsoft debug their applications..........

     

    I love the way the technicians immediately think that this is a coding error perpertrated by the poor victim using the VS designer....believe it or not guys some of us like to use RAD tools as they are supposed to make the process quicker....oh dear....they don't do they..........bring back green screens and character based software......we might all sleep easier in our beds!

    Monday, July 09, 2007 12:24 PM
  • I was experiencing the same problem, but seem to have found a solution to this issue:

     

    I was looking at the "Data Sources" toolbox window in my project and noticed there was one data source listed with a "warning" icon (yellow triangle with "!") super-imposed.  This item appeared at the very top of the tree, outside of the project's namespace node.  Apparently I had started to create an Object data source on one of my classes and cancelled it or had an error (don't remember, because I wasn't using that DS). 

     

    Next I opened the "Properties > Data Sources" under Solution Explorer and saw that data source listed there.  I deleted that erroneous data source and left all the other ones alone.  After deleting, everything worked just fine.  Since I hadn't been using that DS, I was lucky not to have been impacted by the delete.

     

    I suspect this error happens when one of the Data Sources in the project is corrupted or otherwise broken, and when VS2005 tries to list that object in the wizards or designers it bombs out.  So if you are getting this error, it's probably because one of your data source project files is corrupted.  Find out which one by looking at the Data Source explorer (on the menu "Data > Show Data Sources") and see if one is listed with a warning icon.  If so, go to Solution Explorer, open the "Properties > Data Sources" folder and delete the ".datasource" file representing the bad DS.

     

    Well I hope this helps some other poor soul out there - good luck!

    Friday, July 13, 2007 5:33 PM
  • I had the same symptoms with the Windows forms designer. Similarly, the "Data>Data Sources" had several warning icons. A coworker had deemed that several objects defined in one of the libraries were not needed and commented all of the code in each of the classes. This of course broke the data sources, hence the warning icons. (Moving the data sources to another library would cause the same problem.)

     

    The designer evidently has a bug in it when it tries to build a list of data sources for selection by the user. It does not correctly handle these "bad" data sources but instead throws the unhandled error ,"Object reference not set to an instance of an object", when it encounters one.

     

    I simply right clicked on each of the bad data sources and removed each one. Once they were all gone, the designer could successfully build the list and the error disappeared.

     

    Wayne

    Thursday, August 09, 2007 4:55 PM
  •  

    Thank you Thak you

     

    I had the same problem;

     

    I saw datasources with the warning icon;

    i deleted them and can now use the designer to set a control's data source.

     

    thank you thank you

     

    pp

     

    Friday, September 21, 2007 4:50 PM
  • I'm having the same problem, however none of the solutions are working for me.  Here is what I'm doing

     

    1. Adding a premade database to the proejct

    2. Drag/drop gridview to my page

    3. Create the data source for the gridview.

     

    The wizard takes me immediately to the tabs used to create the update/select/delete queries.  It doesn't let me select the table/query I want to use.  It just skips a screen. 

     

    Any help would be helpful

    Saturday, November 10, 2007 3:38 AM
  • It did help - good spot - many thanks.

    Saturday, December 08, 2007 9:25 PM
  • Here's another possibility (discovered after much pain... note the Log files were of no help to me as they didn't have any clue as to what the cause of the problem might be):

     

    If for some reason you (or one of your developers Stick out tongue) specify one of your Boolean Report Parameters to have a preceding equals sign (=) then you get the infamous "Object reference not set to an instance of an object" error.

     

    My Report Parameters for the report in question looked as follows:

     

    Name: DataType

    Data type: Boolean

    Prompt: Data Type

    Available values:

    Non-queried bullet selected with grid having two rows as follows:

    Label                Value

    --------------------    --------------

    Effective Date    =False

    Received Date   =True

     

    Default values as follows:

    Non-queried      True

     

    As soon as I modified the "=False" to be just "False" (and did the same for the "=True") the error went away.  Moral of story, it appears that this error is returned for a multitude of reasons (thanks Microsoft) including this one... so, double-check your parameters and confirm they're set up correctly.  In this case an extra "=" caused the error but I would not be surprized if other seemingly "innocuous" trappings cause it to flare up.

    Thursday, December 20, 2007 9:06 PM
  •  

    OK I'm getting this error after converting an ASP.Net 1.1 project to 2.0.

     

    In the original project I used SQLAdapters to fill datasets. The filling took place in the default.aspx.vb file, and in the Page Load event the datagrids were bound to the datasets.

     

    Now the page won't even display, I only get the Object Reference error.

     

    Any ideas? Should I just rewrite the whole page?

    Friday, February 01, 2008 6:51 PM
  • Thank you for the help! Worked for me =)
    Wednesday, July 23, 2008 1:15 PM
  • I don't seem to have all of these things like 'show data sources' ...

    I'm using Visual Studio .NET 2005

    • Edited by Xsaron Monday, August 11, 2008 10:39 AM confusing :-)
    Monday, August 11, 2008 10:30 AM
  • when you are trying to get data form the database
    check the values in query string or session


    Bashir Ahmad
    Saturday, August 23, 2008 8:53 AM
  • if you are having problems with the dataset designer then it is defintiely worth trying the following

    start>run>>regsvr32 query.dll

    not sure why the graphical designer gets screwed up but this has helped me a couple of times
    • Proposed as answer by Ken6 Thursday, November 25, 2010 7:44 AM
    Sunday, September 13, 2009 12:07 PM
  • Pssssst.
    This thread is old.  check the date
    Mark the best replies as answers. "Fooling computers since 1971."
    Sunday, September 13, 2009 2:22 PM
  • You have got to be kidding me. I couldn't add a data source to my project so on a lark i tried the "regsvr32 query.dll" and now I can work with the data..

     

    ps I DO NOT CARE HOW OLD THIS THREAD IS.  

    Thursday, November 25, 2010 7:44 AM
  • recreating the list object made the error go...funny and irritating thing..wonder why it happens so?
    • Proposed as answer by Mark Monforti Saturday, February 12, 2011 10:18 PM
    Saturday, February 05, 2011 10:33 AM
  • I Make sure you step into your databind when debugging.  This is typiclly a problem when you have code in your ItemDataBound method.  And your FindControl method fails.

     

    Mark

    • Proposed as answer by Mark Monforti Saturday, February 12, 2011 10:20 PM
    Saturday, February 12, 2011 10:20 PM