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();
}
}
}
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
ASP.NET Training
ASP NET Training
ASP.NET Online Training
C# Training
Dot Net Training in Chennai
Dot Net Training institutes in Chennai
ASP.NET Training