Hi,
I am trying to populate a DataGridView using DataReader. But I am unable to bind it.
Cna I know, how do I do it? Can anyone please help?
Thanks,
Sridhar.
Binding DataGridView usin DataReader
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

li yufeng6 reputationPosted May 4, 2006, 12:11 AM EDT
You can use bindingSource.First,you need to use the 'read()' method of DataReader,Store the records into a colleciton object,then you can set the data source of bindingSource with the colleciton,finally,bind the dataGridView with the bindingSource.
sridhar reddy12 reputationPosted May 4, 2006, 3:03 AM EDT
Ajay Rohilla2 reputationPosted Feb 7, 2007, 2:38 AM EST
SqlConnection con = new SqlConnection("Connection String");
con.Open();
SqlCommand com = new SqlCommand("SQL Query", con); SqlDataReader read = com.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable("Table1");ds.Tables.Add(dt);
ds.Load(read,
LoadOption.PreserveChanges, ds.Tables[0]);gridControl1.DataSource = ds.Tables[0];
vijay kumar24 reputationPosted Feb 6, 2008, 12:11 AM EST
sqldatareader sqlreader = new sqldatareader();
sqlreader = commandobject.executereader()
while(sqlreader.read())
{
str = dr["FieldName"];
}
sqlreader.close()