|
|
| What are the various objects in Dataset? |
Dataset has a collection of DataTable object within the Tables collection. Each DataTable object contains a collection of DataRow objects and a collection of DataColumn objects. There are also collections for the primay keys, constraints, and default values used in this table which is called as constraint collection, and the parent and child relationships between the tables. Finally, there is a DefaultView object for each table. This is used to create a DataView object based on the table, so that the data can be searched, filtered or otherwise manipulated while displaying the data.
|
| How can we force the connection object to close after my datareader is closed? |
Command method Executereader takes a parameter called as CommandBehavior where in we can specify saying close connection automatically after the Datareader is close.
pobjDataReader = pobjCommand.ExecuteReader(CommandBehavior.CloseConnection)
|
| I want to force the datareader to return only schema of the datastore rather than data? |
pobjDataReader = pobjCommand.ExecuteReader(CommandBehavior.SchemaOnly)
|
| How can we fine tune the command object when we are expecting a single row? |
Again CommandBehaviour enumeration provides two values SingleResult and SingleRow. If you are expecting a single value then pass "CommandBehaviour.SingleResult" and the query is optimized accordingly, if you are expecting single row then pass "CommandBehaviour.SingleRow" and query is optimized according to single row.
|
| Which is the best place to store connectionstring in .NET projects? |
Config files are the best places to store connectionstrings. If it is a web-based application "Web.config" file will be used and if it is a windows application "App.config" files will be used.
|
| What are the various methods provided by the dataset object to generate XML? |
ReadXML
Reads a XML document into Dataset.
GetXML
This is a function which returns the string containing XML document.
WriteXML
This writes a XML data to disk.
|
| How can we save all data from dataset? |
Dataset has "AcceptChanges" method which commits all the changes since last time "AcceptChanges" has been executed.
|
| How can we check that some changes have been made to dataset since it was loaded? |
For tracking down changes Dataset has two methods which comes as rescue "GetChanges " and "HasChanges".
GetChanges
Returns dataset which are changed since it was loaded or since Acceptchanges was executed.
HasChanges
This property indicates that has any changes been made since the dataset was loaded or acceptchanges method was executed.
If we want to revert or abandon all changes since the dataset was loaded use "RejectChanges".
|
| How can we add/remove ows in "DataTable" object of "DataSet"? |
"Datatable" provides "NewRow" method to ad new row to "DataTable". "DataTable" has "DataRowCollection" object which has all rows in a "DataTable" object. Following are the methods provided by "DataRowCollection" object :-
Add
Adds a new row in DataTable
Remove
It removes a "DataRow" object from "DataTable"
RemoveAt
It removes a "DataRow" object from "DataTable" depending on index position of the "DataTable".
|
| What is basic use of "DataView"? |
|
"DataView" represents a complete table or can be small section of rows depending on some criteria. It is best used for sorting and finding data with in "datatable".
Dataview has the following methods :-
Find
It takes a array of values and returns the index of the row.
FindRow
This also takes array of values but returns a collection of "DataRow". If we want to manipulate data of "DataTable" object create "DataView" of the "DataTable" object and use the following functionalities :-
AddNew
Adds a new row to the "DataView" object.
Delete
Deletes the specified row from "DataView" object.
|
|
|
|
|
|
|