Wednesday, December 23, 2009

How can I sove the problem ';Object reference not set to an instance of an object'; ?

When I execute the code


Dim dr As DataRow


dr = ds.Tables(';tbl_item';).NewRow()


in VB.NET with sql Server 2000 back end there happened an error like


';Object reference not set to an instance of an object'; . So I want an solution for this. Can Any one provide a solutionHow can I sove the problem ';Object reference not set to an instance of an object'; ?
You are trying to reference an object that has not been instantiated. In your case; your DataRow object ';dr';.





Try Dim dr As New DataRow()





Then you should be able to assign values to ';dr'; like you've done in your second line.





Make sure your DataSet object is also instantiated.





I hope this helps. :-)

No comments:

Post a Comment