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

What is the difference between the clone() and copy() methods of the dataset class?

0 Answers  


What is DataReader Object?

0 Answers  


Explain what are acid properties?

0 Answers  


i want 2 pass values(enterd in textbox)to table in sql server without using stored procedure in c#.plz tell me code with an example.

5 Answers   Softcon, Tecra,


How does entity framework work?

0 Answers  






What does ole stand for in excel?

0 Answers  


What is ODP.NET ?

1 Answers   TCS,


How to check if a datareader is closed or opened?

1 Answers  


What are dcl commands?

0 Answers  


Differnce between Stored procedure and user defined functions?

17 Answers   Microsoft, Symphony,


What is an ADO.Net?

0 Answers  


How to find the given query is optimised one or not?

0 Answers  


Categories