Connecting asp.net with Sqlserver

4 Simple Steps to connect asp.net with Sqlserver

1) Declare Connectionstring & SelectCommand
2) Use
SqlDataAdapter from System.Data.SqlClient namespace
3)
Use DataTable is for holding the result set
4) Show Data using a DataControls

string ConnectionString = "Server=(local);Database=pubs;userid=sa;password=sa";
string SelectCommand = "select * from orders";
using (System.Data.SqlClient.SqlDataAdapter dap = new System.Data.SqlClient.SqlDataAdapter(SelectCommand,ConnectionString))
{
DataTable dt = new DataTable();
dap.Fill(dt);
GridView1.DataSource = dt;
GridView1.Databind();
}

SqlDataAdapter automatically open & close the connection ,
DataTable is for holding the result set ,here the order table
Gridview is for displaying data