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
How would you connect to a database by using .NET?
What are all the classes that are available in System.Data Namespace?
How to add an aggregate column?
What are the benefits of ADO.NET?
What are the advantages of using datalist?
How do you update a dataset in ado.net and how do you update database through dataset?
Explain the two fundamental objects in ado.net?
What are the ado.net objects?
What is the executescalar method?
What is meant by ‘transaction’ in a database and what are the ‘properties of transaction’?
What is ado control?
What is the DataTableCollection?
Which method is used to sort the data in ADO.Net?
What are dataproviders?
What are the advantages of oledb compared with other classes?