Can a DataReader be used as a DataSource for a GridView.
If it is so how will you handle paging.

Answer Posted / dinesh sharma

_cmd.Connection = CON; //_cmd is sqlCommand and
CON is Connection
_cmd.CommandText = "select
Book_Code,ISBN,Title_Of_book from Book_Master";
SqlDataReader dr = _cmd.ExecuteReader();
dts.Columns.Add("Book_Code");
dts.Columns.Add("ISBN");
dts.Columns.Add("Title_Of_book"); DataRow drs;
while (dr.Read())
{
drs = dts.NewRow();
drs[0] = dr[0].ToString();
drs[1] = dr[1].ToString();
drs[2] = dr[2].ToString();
dts.Rows.Add(drs);

Application.DoEvents();




}
dataGridView2.DataSource = dts;


dr.Close();
_cmd.Dispose();

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between sqldatareader and sqldataadapter?

715


What is read only and forward only in ado.net?

715


Which is better ole db or odbc?

685


What is serialization and de-serialization in .net? How can we serialize the dataset object?

715


How does ado.net work?

676


What are typed and untyped dataset?

778


Define Execute Reader?

836


What does ole stand for in excel?

848


What are the connected and disconnected modes in ado.net?

698


How do you update database through dataset?

735


Describe datareader object of ado.net with example.

702


What is the difference between a datareader and a dataset?

710


What is oledb driver?

706


What we do with the object of ado.net dataset after using it?

718


Define executenonquery?

703