Can we use data reader to bind gridview?
Answers were Sorted based on User's Feedback
Answer / prasanth
data reader can be used to databind gri view
void Page_Load(Object sender, EventArgs e){ String Q; Sql
command cmd; Sql DataReader dr; SqlConnection conn = new
SqlConnection(); conn.ConnectionString =
ConfigurationManager.ConnectionStrings
["cn"].ConnectionString.ToString(); conn.Open
(); Q = "select * from tablename";
cmd= New Sqlcommand(Q, conn); dr =
cmd.ExecuteReader();
Gridview1.DataSource = dr; Gridview1.DataBind();}
| Is This Answer Correct ? | 17 Yes | 4 No |
Answer / swathi
this is also same as the Dataset.
these are steps:
1. SqlConnection con=new SqlConnection(ConnectionString);
2. SqlCommand com=new SqlCommand("Select * from
TableNAme",con);
3. SqlDataReader dr;
4. con.open();
5. dr=com.ExecuteReader();
6. Datagrid1.DataSource=dr;
7. DataGrid1.DataBind();
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / minhaj
yes, we can bind
but datagrid can
not be backword
because DR is
forward only
| Is This Answer Correct ? | 2 Yes | 0 No |
what will do to avoid prior case?
What is an anonymous method and how is it different from a lambda expression?
What is assembly in .net?
Explain me difference between public and static modifiers?
Please explain the difference between constants and read-only variables?
What are the different types of memory in .net?
What is the advantage of packaging over xcopy in .net?
What is the difference between an abstract class and an interface?
What is lazy initialization?
Which among the following two is best and why? Abstract Class and Interface. What is the major difference in between those two except the discrete methods and methods with function definition.
What is interface and abstract class in .net?
questions on various scenarios on exception handling? like for example.... try { a; b; ...exception occurs here...what happens...will catch execute or will finally execute...will c execute c; } catch { a; b; c; } fianlly { a; b; }