Page 1 of 1

How to bind data to a DataGridView?

Posted: Thu 15 Mar 2012 21:12
by bclayshannon
I can retrieve data this way:

Code: Select all

            while (myReader.Read())
            {
                MessageBox.Show(myReader.GetString(0)); 
             }
...but I really want to put all of the data into a DataGridView control. Is that possisble? If so, how?

Posted: Tue 20 Mar 2012 08:27
by Pinturiccio
bclayshannon wrote:...but I really want to put all the data into a DataGridView control. Is that possisble? If so, how?
You cannot bind data from DataReader to DataGridView control. As a workaround, you can put all of the data into DataTable and then bind Datatable to DataGridView control.