Code to bind gridview with DataAdapter

Code to bind gridview with DataAdapter using Asp.Net

->The ConnectionString index value will get from web.config file.

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)

Public void bindRecord()
SqlConnection con =new SqlConnection(ConfigurationManager.
SqlCommand cmd=new SqlCommand();
cmd.commandText="SELECT * FROM tablename";
SqlDataAdapter da=new SqlDataAdapter(cmd);
Dataset ds=new Dataset();


Related Articles

What is GridView control and how to bind GridView to data?

What is a GridView control in Want to learn how to connect GridView to a database? This article will teach you more about the databound control GridView, properties and events of GridView and binding a GridView control to data.

How to add Buttons in Data GridView?

Want to add buttons to the GridView control in Need to execute a set of statements when the user clicks on the button in the GridView? Learn how to add controls like button to the GridView control and write C# code for user activities performed like Clicking of Buttons in the GridView.

More articles: Gridview databind Gridview data source Gridview


Guest Author: jazz05 Feb 2014

use cmd.ExecuteReader();
instead of cmd.ExecuteNonQuery();

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: