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
What is the role of the dataset object in ado.net?
Can we do database operations without using any of the ado.net objects?
What is concurrency? How will you avoid concurrency when dealing with dataset? (One user deleted one row after that another user through his dataset was trying to update same row. What will happen? How will you avoid the problem?)
What is ado.net code?
What is DataReader Object?
Define bubbled event?
What is the difference between Dataset. clone and Dataset.copy?
Give few examples of datareader that is used in different dataproviders.
How to maintain the relation between two tables in ADO.NET?
What is DataRowCollection?
What is the return type of executescalar?
Which property is used to check whether a DataReader is closed or opened?
How can we load multiple tables in a dataset?
Which architecture does Datasets follow?
What is ado control?