Can we use data reader to bind gridview?

Answers were Sorted based on User's Feedback



Can we use data reader to bind gridview?..

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

Can we use data reader to bind gridview?..

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

Can we use data reader to bind gridview?..

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

Post New Answer

More Dot Net General Interview Questions

What's the use of system.diagnostics.process class in .net?

0 Answers  


Explain the differences between server-side code and client-side code.

0 Answers  


What is garbage collection and how it works ?

0 Answers  


what is GAC?

1 Answers   Manhattan,


Write an StoredProcedure to get the values of a column within a date range.

1 Answers   Deloitte,






What does stateless mean?

0 Answers   BirlaSoft,


What is your observations between vb.net and vc#.net?

0 Answers  


How to implement getcommon method in class a? Are you seeing any problem in the implementation?

0 Answers  


can any one tel me the complete Testing Procedure of any one simple PROJECT i mean either web/windows based application?

0 Answers  


Explain the two different types of typecasting?

1 Answers  


Why MVC programming model preferred?

1 Answers  


What is the use of trace utility?

1 Answers  


Categories