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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
vijay kumarPosted Feb 6, 2008, 5:11 AM
sqldatareader sqlreader = new sqldatareader();
sqlreader = commandobject.executereader()
while(sqlreader.read())
{
str = dr["FieldName"];
}
sqlreader.close()
Ajay RohillaPosted Feb 7, 2007, 7:38 AM
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];
sridhar reddyPosted May 4, 2006, 7:03 AM
li yufengPosted May 4, 2006, 4:11 AM
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.