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 namespace in ado.net?
What is the DataTableCollection?
What is the meaning of object pooling?
Explain what is datagrid with an example?
How to aggregating data across related tables?
Explain the difference between sqlcommand object and command behavior object?
What is sql connection in ado.net?
What are dataproviders?
What is ado and rdo?
What is the usage of the dataset object in ado.net?
Explain the advantages and disadvantages of using datalist?
What is the meaning of executenonquery?
Name which operations can you not perform on an ado.net dataset?
What is connection pooling and what is the maximum pool size in ado.net connection string?
What is the difference between the clone() and copy() methods of the dataset class?