Object reference not set as an instance of an object. Datatable [duplicated]

0

What I want is to fill DataTable with addresses of my images, and this table will be increased according to the number of files in a folder in which I store my images, only that I get an error that I could not solve and here is my code.

Table Code:

DataTable dTable = new DataTable();
dTable.Columns.Add("Ruta");
DataRow dr = dTable.NewRow();
dr["Ruta"] = "Imagen";
dTable.Rows.Add(dr);
dataInfo.DataSource = dTable;

At the moment I should just show a table with the route column and the image value, but it marks the error of the title.

  

Reference to object not established as an instance of an object.

The error marks me on the following line:

dataInfo.DataSource = dTable;
    
asked by David 20.02.2017 в 23:07
source

2 answers

0

if dataInfo is a DataSet you must:

dataInfo[0]

reference the table where you assigned it why a dataset can save multiple tables

    
answered by 21.02.2017 в 00:39
0

Your control is not being instantiated in the Initialize method of the form.

In short, Visual Studio is not doing its job.

The simplest thing is to delete the DataGridView from the form and create it again so that Visual Studio can put the correct code.

    
answered by 20.02.2017 в 23:38