mi1an
mi1an's Blog

mi1an's Blog

DataAdapter & DataSet in C#

DataAdapter & DataSet in C#

mi1an's photo
mi1an

Published on Nov 4, 2021

1 min read

using System;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    static string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\mi1an\source\repos\DisplayData\DisplayData\App_Data\Database.mdf;Integrated Security=True";
    SqlConnection con = new SqlConnection(cs);
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataAdapter sda = new SqlDataAdapter("Select * From Students", con);
        DataSet ds = new DataSet();

        sda.Fill(ds); // Now Dataset is Filled with SqlDataAdapter.

        // Let's See DataSet Clean Method
        ds.Clear(); // It is clear out DataSet Table. after Filling it.

        //Bind Dataset to Gridview
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}

Download PDF : Click Here

 
Share this