How to bind data to a grid view in C#.net

How to bind data to a grid view in C#.net 

When we need to show data from database we have to use a front end control to show data. connecting grid view control of web based application to the database is called binding

 SqlConnection conn = new SqlConnection(constring);

        string query = " Select * from table";

        SqlCommand sqlCmd = new SqlCommand(query, conn);
        conn.Open();

        SqlDataReader reader = sqlCmd.ExecuteReader();

        GridView1.DataSource = reader;

        GridView1.DataBind();


        conn.Close();




Comments