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 ado.net in mvc?

689


Explain the architecture of ado.net?

820


Do you use stored procedure in ado.net?

790


What is connection in ado.net?

729


Explain sqlconnection object?

779


What is difference in record set and dataset?

759


What is data adapter in ado.net with example?

724


What is Data view?

803


What is dbcontext and dbset in entity framework?

701


Explain what are acid properties?

776


What is data access pattern?

690


What is the namespaces being used to access oracle database?

758


What is sqlconnection and sqlcommand?

736


What is the full form of ado.net?

760


Which architecture does Datasets follow?

815