In C#, we can work in two different ways with the database connectivity. As we know when we create software or any website or any other application which is connected to the database we must need to make connection to the database to get data. Here we can get data in two different ways.
Either it may be connected architecture where we go and connect to the database and get data or disconnected architecture where we connect to the database first time and get all data in an object and use if it is required. We can perform any action like insert, update, and search on this disconnected architecture.
In this type of disconnected architecture we don’t need to connect always when we want to get data from the database. We can get data from dataset and DataSet is a collection of datatables. We can store the database table, view data in the DataSet and can also store the xml value in dataset and get it whenever required, the data retrieved from database can be accessed even when connection to the database was closed. It is built on classesconnection, dataadapter, commandbuilder, dataset and dataview.
To achieve this we need to use DataAdapter which work as a mediator between Database and DataSet.
Example
1. public DataSet GetEmployeeData()
2. {
3. SqlConnection conString = new SqlConnection("myconnection");
4. conString.Open();
5. SqlCommand cmdQuery = new SqlCommand("Select * from Employee", conString);
6. SqlDataAdapter sda = new SqlDataAdapter(cmdQuery);
7. DataSet dsData = new DataSet();
8. sda.Fill(dsData);
9. return dsData;
10. }
DataReader
It is a type of connected architecture, which means when we require data from the database we need to connect with database and fetch the data from the database. We can use if we need updated data from the database in a faster manner. DataReader is Read/Forward only that means we can only get the data but we cannot update or insert the data into the database. It fetche the record one by one within the database.
In connected architecture, we know the connection must be opened to access the data retrieved from the database. It is also built on the classes connection, command, datareader and transaction.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Nishi Tiwari
22-Jan-2020In C#, we can work in two different ways with the database connectivity. As we know when we create software or any website or any other application which is connected to the database we must need to make connection to the database to get data. Here we can get data in two different ways.
Either it may be connected architecture where we go and connect to the database and get data or disconnected architecture where we connect to the database first time and get all data in an object and use if it is required. We can perform any action like insert, update, and search on this disconnected architecture.
We can use two C# objects to achieve this, first one is DataSet and other one is DataReader.
DataSet
In this type of disconnected architecture we don’t need to connect always when we want to get data from the database. We can get data from dataset and DataSet is a collection of datatables. We can store the database table, view data in the DataSet and can also store the xml value in dataset and get it whenever required, the data retrieved from database can be accessed even when connection to the database was closed. It is built on classesconnection, dataadapter, commandbuilder, dataset and dataview.
To achieve this we need to use DataAdapter which work as a mediator between Database and DataSet.
Example
DataReader
It is a type of connected architecture, which means when we require data from the database we need to connect with database and fetch the data from the database. We can use if we need updated data from the database in a faster manner. DataReader is Read/Forward only that means we can only get the data but we cannot update or insert the data into the database. It fetche the record one by one within the database.
In connected architecture, we know the connection must be opened to access the data retrieved from the database. It is also built on the classes connection, command, datareader and transaction.
Example