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

How to convert a .NET object into COM operabililty?

761


  • Accomm
  • i have this code.now on server side i want to compare this id(Accommodation) value and want id i.e.Accommodation.visible=true;

    1597


    Differences between namespace, class, assembly?

    791


    What is the procedure to add assemly to gac to make it shared one?

    759


    What does cli do?

    721


    What is web.config in .net?

    783


    Difference abstract class and interface in .net?

    826


    What is iis? Have you used it?

    769


    What is different between webusercontrol and in webcustomcontrol?

    730


    How to Create and Consume a Web Service?

    2983


    What is meant by managed and unmanaged code?

    882


    What is a manifest in .net?

    803


    How do you view the methods and members of a dll?

    848


    Write the .net syntax for 'while loop'?

    794


    Is .net core installed?

    791