DataReader:
It is read only format, we can't update records.
It is connection oriented, whenever data bind from database that need connection and then connection is disconnected.
Code Behind:
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("Data Source=database;Integrated Security=true;Initial Catalog=catalog");
- {
- con.Open();
- SqlCommand cmd = new SqlCommand("Select record FROM table", con);
- SqlDataReader dr = cmd.ExecuteReader();
- grdvw.DataSource = dr;
- grdvw.DataBind();
- con.Close();
- }
- }
Dataset:
It is connectionless oriented.
Whenever we bind data from database. It connects indirectly to the database and then disconnected. Its easily read and write data from database.
Code Behind:
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("Data Source=datasource;Integrated Security=true;Initial Catalog=catalog");
- con.Open();
- SqlCommand cmd = new SqlCommand("select record from table", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- da.Fill(ds);
- grdvw.DataSource = ds;
- gvdvw.DataBind();
- }
DataTable:
DataTable represents a single table in the database.
It has rows and columns. There is no much difference between dataset and datatable, Dataset is simply the collection of datatables.
Code Behind:
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("Data Source=datasource;Integrated Security=true;Initial Catalog=catalog");
- con.Open();
- SqlCommand cmd = new SqlCommand("select record from table", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- grdvw.DataSource = dt;
- gvdvw.DataBind();
- }
DataAdapter:
Dataadapter is a disconnected oriented architecture.
DataAdapter is like a mediator between DataSet (or) DataTable and database. This dataadapter is used to read the data from database and bind to dataset.
- .cs page
- protected void Bind()
- {
- SqlConnection con = new SqlConnection("Data Source=datasource;Integrated Security=true; Initial Catalog=catalog");
- con.Open();
- SqlCommand cmd = new SqlCommand("select record from table", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- da.Fill(ds);
- grdvw.DataSource = ds;
- gvdvw.DataBind();
- }