Incorrect binding of DataGridView to DataSet

The DataGridView associated with this code does not display information as expected:

dataGridView1.DataSource = ds;

here is the code for ds:

public DataSet ConnectandReadList()
        {
            DataSet ds = new DataSet();

            string connection_string="Data Source=hermes;database=qcvalues; Integrated Security=SSPI;";            

            using (var myConnection = new SqlConnection(connection_string))
            {

                myConnection.Open();
                var command = new SqlCommand(InitializeQuery(), myConnection);
                var adapter = new SqlDataAdapter(command);

                adapter.Fill(ds);
            }


            return ds;
        }
+3
source share
2 answers

Try to bind to the table inside the dataset: dataGridView1.DataSource = ds.Tables[0];

From the documentation for the DataGridView.DataSource property, you can also bind to DataSetand use the property DataMember:

, , DataMember , .

, "Table", .

+4

ds DataSet?

, DGV DataMember DataTable DataSet DataTet DataTable DataSource.

+3

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


All Articles