In this article I will explain the following ADO.NET concepts: DataTable, DataSet, DataReader and DataAdapter. Also, learn about some differences between these ADO.NET concepts.
DataTable:
- DataTable represents a single table in a database.
- In this show row and column.
- DataSet is a collection of data tables.
- In this store data record.
DataTable representation in .aspx.cs code,
- protected void BinddataTable()
- {
- SqlConnection con = new SqlConnection("your database connection string");
- con.Open();
- SqlCommand cmd = new SqlCommand("Write your query or procedure", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- grid.DataSource = dt;
- grid.DataBind();
- }
- DataSet can hold multiple tables at a time.
- DataSet allow data access to easily read or write data operations in / from the database.
- DataSet data stores in local system.
- DataSet hold multiple rows at a time.
- DataSet use more memory.
- DataSet maintain relation.
- DataSet bind data from the database.
DataSet representation in .aspx.cs code,
- protected void BindDataSet()
- {
- SqlConnection con = new SqlConnection("your database connection string ");
- con.Open();
- SqlCommand cmd = new SqlCommand("Write your query or procedure ", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- da.Fill(ds);
- grid.DataSource = ds;
- grid.DataBind();
- }
- DataReader hold only one table at a time.
- DataReader only provide read only access mode and cannot write data.
- DataReader not required local storage to data store.
- DataReader hold one row at time.
- DataReader uses less memory.
- DataReader do not maintain relation.
DataReader representation in .aspx.cs code,
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("your database connection string ");
- con.Open();
- SqlCommand cmd = new SqlCommand("Write your query or procedure ", con);
- SqlDataReader dr = cmd.ExecuteReader();
- grid.DataSource = dr;
- grid.DataBind();
- }
- DataAdapter is a disconnected oriented architecture.
- DataAdapter is one type of bridge between dataset and database.
- DataAdapter is used to read the data from DataTable and bind to DataSet.
DataAdapter representation in .aspx.cs code,
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("your database connection string ");
- con.Open();
- SqlCommand cmd = new SqlCommand("Write your query or procedure ", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- da.Fill(ds);
- grid.DataSource = ds;
- grid.DataBind();
- }


Santhakumar MunuswamyPosted Oct 17, 2015, 11:20 PM EDT
Good one
Priyaranjan K STOP 100Posted Oct 14, 2015, 8:20 AM EDT
Good One ji ..
Mukesh KumarPosted Oct 13, 2015, 9:29 PM EDT
Greate work, thanks for sharing
Rajeesh MenothPosted Oct 13, 2015, 8:27 PM EDT
Nice One !!
Nilesh JadavPosted Oct 13, 2015, 8:08 PM EDT
Nice one sir !!
Harshad PansuriyaPosted Oct 13, 2015, 7:55 PM EDT
Nice one
Gowtham KTOP 100Posted Oct 13, 2015, 6:40 PM EDT
Good one
Ravi PatelPosted Oct 13, 2015, 5:30 PM EDT
good article
Sujeet SumanPosted Oct 13, 2015, 9:56 AM EDT
Nice Article................