Display data in GridView in asp.net

Display data in GridView in asp.net:
using System.Data;

using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)

{
SqlConnection cn = new SqlConnection("Server=localhost;database=test;uid=sa;pwd="); SqlDataAdapter da = new SqlDataAdapter("Select * from Products", cn);
DataSet ds = new DataSet();
try
{
da.Fill(ds); GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cn.Close();
da.Dispose();
ds.Dispose();
}
}
}

Comments

Popular posts from this blog

Very fast test data generation using exponential INSERT

Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture

What's New in ASP.NET and Web Development