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

Answers were Sorted based on User's Feedback



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

Answer / rahul singhal

yes u can use data reader to fill gridview with while
function. and paging depends upon the datagrid property. if
u use custom paging there in no possibility with data
reader. u will have to use data table to fill data grid and
data table should be filled through data reader.

Is This Answer Correct ?    9 Yes 1 No

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

Answer / karthikeyant

some changes made in the above code

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();
DataTable dataTable = new DataTable();
dataTable.Load(dr);
dr.Close();
_cmd.Dispose();

dataGridView2.DataSource = dataTable;

Is This Answer Correct ?    7 Yes 0 No

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

Answer / 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

More ADO.NET Interview Questions

How to Read, Add, Update and Delete record in Entity Framework ?

0 Answers  


What Is Difference Between Ado And Ado.net?

0 Answers   BirlaSoft,


What are all components of ADO.Net data provider?

0 Answers  


suppose we using gridview contrl,with sqldatasource.in that for birth date how can we take validation contrl for dd/mm/yy formator how we assign regular expression for same

9 Answers   TCS,


What are the advantages and drawbacks of using ado.net?

0 Answers  


Describe ado.net object model in detail.

0 Answers  


Sequence to connect and retrieve data from database useig dataset ?

6 Answers   MMTS,


What is ole word?

0 Answers  


What is an orm, and why would you use one instead of plain old ado.net?

0 Answers  


What is difference between dataset and datatable?

0 Answers  


What is the role of clr?

0 Answers  


What are the different row versions available?

3 Answers  


Categories