Can we use data reader to bind gridview?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What should you do to store an object in a viewstate?

817


What is the transport protocol you use to call a seb service soap?

784


What is lambda expressions in c#?

831


What does jit compilation do in .net?

837


What operating systems does the .net framework run on?

797


What is the difference between a class and an object, and how do these terms relate to each other?

809


What is an exe and a dll?

878


Difference between dispose and finallize method?

943


how can i create a table from front end to back end in wabe page?

1724


What are the different types of memory in .net?

862


What is new in .net core?

729


Explain what is the difference between web application and enterprise application?

819


Explain about .NET services?

846


What is .net assembly?

823


How to instantiate a delegate?

1878