DataReader fetches one record at a time..when ever you all theRead() function the next record if there is any gets fetched..now for this the connection to the database has to be open when the read function is called.. on the other Hand DataTable fetches all the records when you call the Fill() function of the DataAdapter. It keeps the records in memory so that you can use it latter without been connected to the database..This is an Example of .NET Disconnected Architecture .. DataReader is lighter than DataTable.
You can see the actual difference between DataTable & dataReader below: 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. eg. Code: protected void BindGridview() { SqlConnection con = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test"); conn.Open(); SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); gridview1.DataSource = dt; gvidview1.DataBind(); } DataReader DataReader is used to read the data from database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset. Generally we will use ExecuteReader object to bind data to datareader. To bind DataReader data to GridView we need to write the code like as shown below: eg. Code: Protected void BindGridview() { using (SqlConnection conn = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test")) { con.Open(); SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn); SqlDataReader sdr = cmd.ExecuteReader(); gvUserInfo.DataSource = sdr; gvUserInfo.DataBind(); conn.Close(); } } Holds the connection open until you are finished (don't forget to close it!). Can typically only be iterated over once Is not as useful for updating back to the database
Data Reader -Its an connection oriented, whenever you want fetch the data from database, you need the connection,after fetch the data connection is disconnected. -Its an Read only format, you can't update records. -DataReaders provide a very efficient way to access data, and can be thought of as a Firehose cursor from ASP Classic, except that no server-side cursor is used. Data Table -A DataTable object represents a single table in the database. It has a name rows and columns. -The DataTable also contains a collection of Constraint objects that can be used to ensure the integrity of the data.
A DataReader is an object returned from the ExecuteReader method of a DbCommand object. It is a forward-only cursor over the rows in the each result set. Using a DataReader, you can access each column of the result set, read all rows of the set, and advance to the next result set if there are more than one. 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.
Difference between DataReader, Dataset, DataTable and DataAdapter in ASP.NET: http://www.c-sharpcorner.com/blogs/...dataset-dataadapter-and-datatable-in-c-sharp1
Records cannot be updated because it is a read-only format. It is connection-oriented; whenever data is retrieved from a database, a connection is required. Since it's in read-only format, we can't update it. Data Reader is used to read data from databases, and its connection-oriented architecture is read-only while fetching data from databases. When compared to a dataset, a data reader will retrieve the data quite quickly. Typically, we'll connect data to a data reader using an Execute Reader object. Where as Data Table represents a single table in the database It has rows and columns. There is no much difference between dataset and data table, Dataset is simply the collection of data tables. A single database table is represented by a Data Table. It has columns and rows. Datasets and data tables are nearly identical; a dataset is essentially a collection of data tables.