Reputation: 4319
I have a gridview. Its datasource is set as follows.
dtTable
is a datable in which the values for the table will be retrieved. But when setting dtTable
as datasource I get an error "Object reference not set to an instance of an object". What may be the reason for this?
gridview.Datasource = dtTable
gridview.Databind()
Upvotes: 0
Views: 550
Reputation: 8421
You won't get a null reference exception if the data table is null, you will get one if the gridview is null. That's assuming that one of these two lines are actually generating the exception.
Upvotes: 0
Reputation: 135463
Take a look at where the dtTable
variable is initialised. Is it coming back as Nothing
? Maybe you are getting another error that is being ignored. Probably the dtTable
is the cause of the problem.
Upvotes: 1
Reputation: 2703
Make sure that dtTable has the records you need. This error usually means that dtTable is null.
Upvotes: 1