Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

Object reference not set to an instance of an object in
this code
Dim dtSchema As DataTable = dr.GetSchemaTable()
Posted
Updated 9-Oct-11 21:16pm
v2
Comments
P.Salini 10-Oct-11 3:24am    
don't re-post your question
koolprasad2003 10-Oct-11 8:42am    
your datareader must be NULL

Your variable dr needs to point to an object.
 
Share this answer
 
Object reference not set to an instance of an object
this means
dr in your code is null
so check the query is retrieving any results or not
 
Share this answer
 
dr.GetSchemaTable()
returns null value .
it returns nothing thatswhy error came
 
Share this answer
 
have you declared dr ?
You dont have declared dr thats y the error comes..
 
Share this answer
 
A data table object is a reference type that has
to have a value. You don’t have to use the “new” keyword, but by
default the value is Nothing/null. You would have to at least
initialize to dtSchema = new DataTable, before
it will compile in C#, or run without exception in VB.Net
 
Share this answer
 
From that code fragment, it can only be dr that is not valid - you need to look at your previous code and work out why it has a value of nothing

Try putting a breakpoint at the start of the function, and single stepping through, if you can't spot it from the code.
 
Share this answer
 

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