DataBase Design
Default.aspx
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
/* dataset */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd=new SqlCommand("select *from customers", con);
con.Open();
da=new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds,"customers");
GridView1.DataMember = "customers";
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
/* DataTable */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd = new SqlCommand("select *from customers", con);
con.Open();
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
protected void Button2_Click1(object sender, EventArgs e)
{
/* datareader */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd = new SqlCommand("select *from customers", con);
con.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
}
Output:
Default.aspx
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
/* dataset */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd=new SqlCommand("select *from customers", con);
con.Open();
da=new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds,"customers");
GridView1.DataMember = "customers";
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
/* DataTable */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd = new SqlCommand("select *from customers", con);
con.Open();
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
protected void Button2_Click1(object sender, EventArgs e)
{
/* datareader */
con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
cmd = new SqlCommand("select *from customers", con);
con.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
}
Output:
No comments:
Post a Comment
Thank you for visiting my blog