DIFFERENCE BETWEEN DATAREADER AND DATASET
===================================================
Answer:
DataReader
===========
DataReader is like a forward only recordset. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them. DataReader will be the best choice where we need to show the data to the user which requires no transaction. As DataReader is forward only so we can't fetch data randomly. .NET Data Providers optimizes the datareader to handle huge amount of data.
DataSet
=======
DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas.
DataSet is always a bulky object that requires a lot of memory space compare to DataReader. We can say that the DataSet is a small database because it stores the schema and data in the application memory area. DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database.
URL:
http://www.dotnetfunda.com/interview/exam13-difference-between-dataset-and-datareader.aspx
A DataReader works in a connected environment, whereas DataSet works in a disconnected environment.
A DataReader object represents a forward only, read only access to data from a source. It implements IDataReader & IDataRecord interfaces. For example, The SQLDataReader class can read rows from tables in a SQL Server data source. It is returned by the ExecuteReader method of the SQLCommand class, typically as a result of a SQL Select statement. The DataReader class' HasRows property can be called to determine whether the DataReader retrieved any rows from the source. This can be used before using the Read method to check whether any data has been retrieved.
Example
Dim objCmd as New SqlCommand("Select * from t_Employees", objCon)
objCon.Open()
Dim objReader as SqlDataReader
objReader = objCom.ExecuteReader(CommandBehavior.CloseConnection)
If objReader.HasRows = True then
Do While objReader.Read()
ListBox1.Items.Add(objReader.GetString(0) & vbTab & objReader.GetInt16(1))
Loop
End If
objReader.Close()
(NOTE: XmlReader object is used for Forward only Read only access of XML).
A DataSet represents an in-memory cache of data consisting of any number of inter-related DataTable objects. A DataTable object represents a tabular block of in-memory data. Further, a DataRow represents a single row of a DataTable object. A Dataset is like a mini-database engine, but its data is stored in the memory. To query the data in a DataSet, we can use a DataView object.
Example
Dim objCon as SqlConnection = New SqlConnection("server=(local);database=NameOfYourDb;user id=sa; password=;)
Dim da as New SqlDataAdapter
Dim ds as DataSet = New DataSet
da.SelectCommand.Connection = objCon 'The Data Adapter manages on its own, opening & closing of connection object
da.SelectCommand.CommandText = "Select * from t_SomeTable"
da.Fill(ds,"YourTableName")
Suppose you want to bind the data in this dataset to a gridview
Gridview1.DataSource = ds
Gridview1.DataMember = "YourTableName"
Gridview1.Databind()
URL
http://www.dotnetuncle.com/Difference/111_DataReader_Dataset.aspx
================================================================================
Difference between Repeater, Datalist and GridView Control
URL:http://www.dotnetspider.com/resources/29917-Difference-between-Repeater-Datalist.aspx
In ASP .NET basically there are 3 kinds of the Data Presentation Controls.
1. GridView (or DataGrid) control
2. DataList control
3. Repeater control
When we talk about usage of one Data Presentation Controls then many of us get confused about choosing one. When you need to use one of the data Presentation Control then You have to see what kind of behavior you need in your Data Display.
1. Do you want to show Data in many Pages or in one page?
2. Do you have to Display more then one column in a Row ?
3. Do you want to have a Row repeating Possibility?
4. Will users be able to update, Insert and delete the Data?
Features of a GridView
•Displays data as a table
•Control over
–Alternate item
–Header
–Footer
–Colors, font, borders, etc.
–Paging
•Updateable
•Item as row
Features of Repeater
•List format
•No default output
•More control
•More complexity
•Item as row
•Not updateable
Features of DataList
•Directional rendering
•Good for columns
•Item as cell
•Alternate item
•Updateable
==========================================================
DIFFERNCE BETWEEN DATATABLE AND DATASET
A DataSet is an in memory representation of data,It containing one or more DataTables.
A DataTable is an in-memory representation of data, typically retrieved from a database or XML source.
A Dataset is like a Container for Datatables because every dataset has a datatable contained inside it and a Datatable is like a table you have in SQL and a Dataset its like a Database that contain table(Datatable)
URL
http://www.dotnetfunda.com/forums/thread615-what-is-the-difference-between-datatable-and-dataset.aspx
==============================================================================
No comments:
Post a Comment