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()
-
Make sure that dtTable has the records you need. This error usually means that dtTable is null.
-
Take a look at where the
dtTablevariable is initialised. Is it coming back asNothing? Maybe you are getting another error that is being ignored. Probably thedtTableis the cause of the problem. -
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.
0 comments:
Post a Comment