Gridview row causes error

Let's start by debugging someone's code :-) An error occurs when a code subroutine tries to export data from gridview to an excel file.

GridView gv = new GridView();
Table table = new Table();
int maxRow = 60000;
int gvrow = Data().Tables[0].Rows.Count;  

An error occurs in Data (). Tables [0] .Rows.Count

Error in the nearest window
:? Data(). Tables [0] .Rows.Count
In System.Data.dll, the first exception of type "System.FormatException" 'Data ()' has a value of null

Error message:
Correction System.NullReferenceException was not processed by user code Message = "The reference to the object is not installed in the object instance."

Any ideas what is wrong here?

+3
3

Data() null. .

+2

, ( Data()?), , Data() - null , , .

0

It sounds like you just need to check that Data () is not null before trying to access the properties.

0
source

Source: https://habr.com/ru/post/1759209/


All Articles