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 is PageIndex in DataGrid?What is the event used in the Datagrid for while moving from one page to another page in the Grid?write code for it

2 Answers  


<li id="Accomodation" runat="server" visible="false"><a href="../searchaccommodation.aspx?">Accomm</a></li> i have this code.now on server side i want to compare this id(Accommodation) value and want id i.e.Accommodation.visible=true;

0 Answers  


What is a web service in .net?

0 Answers  


Difference between assembly manifest & metadata

2 Answers  


What are Satellite Assemblies? How you will create this? How will you get the different language strings?

3 Answers  






When developing a Windows service for .NET, which namespace do you typically look in for required classes?

1 Answers  


Can you configure a .NET Remoting object via XML file?

1 Answers  


What is a garbage collector?

0 Answers  


What is the difference between encrypting a password and applying a hashing?

0 Answers  


Which Namespace is used to to achieve MultiThreading in .NET?

0 Answers  


How do you turn off cookies for one page in your site?

3 Answers   Siebel Systems,


How to produce an assembly?

0 Answers  


Categories