Click here to Skip to main content
15,904,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Object reference not set to an instance of an object. in Line 68: while (dr.Read()) i do not understand that error please help pple!!!
Posted
Updated 19-Sep-12 12:27pm
v2
Comments
Kenneth Haugland 19-Sep-12 18:44pm    
Can I se the declaration of dr?
[no name] 19-Sep-12 20:28pm    
The error is perfectly clear. You are trying to use an object that is null.
Sergey Alexandrovich Kryukov 20-Sep-12 0:24am    
Right, it the line is shown correctly, there is no room for guesswork.
--SA
Rockstar_ 20-Sep-12 0:25am    
please assign the dr with some value...

1 solution

If you are sure that the exception is thrown exactly in that line, it can only mean that dr is equal to null. Check up where this object is constructed and make sure it's not null at the moment of de-referencing; or change the logic of the code to check if (dr != null) … to use it only when it is not null. Always run it under debugger to make sure all object gets appropriate value.

Actually, you should use the debugger whenever you have a slightest concern about your run-time behavior (not only when you have an unexpected exception), and also before you ask a question. Do your homework to get the most from the help you may get.

—SA
 
Share this answer
 
v3
Comments
CodeHawkz 19-Sep-12 23:59pm    
Correct answer :) My 5

Just a small note, you've used '==', it should be '=' :)
Sergey Alexandrovich Kryukov 20-Sep-12 0:22am    
Thank you very much.
No, I meant "==", not "=". This is not a part of the code, but the part of statement meaning "that dr is equal to null". Well, to avoid confusion, I'll replace it with words...
--SA
CodeHawkz 20-Sep-12 0:45am    
hehe, I got it but thought others might not, that's why :)
Sergey Alexandrovich Kryukov 20-Sep-12 0:47am    
Reflection can cause the avalanche effect; did you think about it?
--SA
CodeHawkz 20-Sep-12 1:02am    
agreed :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900