N
N
ninetiledfox2021-08-27 13:39:01
Windows Forms
ninetiledfox, 2021-08-27 13:39:01

An object reference does not point to an instance of an object. How to fix?

class ReportClient
{
public SqlConnection connection = new SqlConnection (ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
public SqlDataAdapter adapter;

public ReportClient()
{
}

public void DisplayClientData(DataGridView dataGridView1)
{
connection.Open();
DataTable dt = new DataTable();
adapter = new SqlDataAdapter("select * from Client", connection);
adapter.Fill(dt);
dataGridView1.DataSource = dt;
connection.Close();
}

}

Writes that dataGridView passes the value null, but there is data in the table, or where I missed something, before that I used the same piece of code in another program, everything worked without failures

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question