Sie sind auf Seite 1von 4

ADO.

NET
ADO.NET is a data access technology from Microsoft .Net Framework , which provides communication between relational and non-relational systems through a common set of components. ADO.NET consists of a set of Objects that expose data access services to the .NET environment.

The ADO.NET Framework supports two models of Data Access Architecture, Connection Oriented Data Access Architecture and Disconnected Data Access Architecture. Connected Architecture of ADO.NET The architecture of ADO.net, in which connection must be opened to access the data retrieved from database is called as connected architecture. Connected architecture was built on the classes connection, command, datareader and transaction. Connected architecture is when you constantly make trips to the database for any CRUD (Create, Read, Update and Delete) operation you wish to do. This creates more traffic to the database.

Disconnected Architecture in ADO.NET The architecture of ADO.net in which data retrieved from database can be accessed even when connection to database was closed is called as disconnected architecture. Disconnected architecture of ADO.net was built on classes connection, dataadapter, commandbuilder and dataset and dataview. Disconnected architecture is a method of retrieving a record set from the database and storing it giving you the ability to do many CRUD (Create, Read, Update and Delete) operations on the data in memory, then it can be re-synchronized with the database when reconnecting. A method of using disconnected architecture is using a Dataset.

Choosing a DataReader or a DataSet

When you decide whether your application should use a DataReader or a DataSet , consider the type of functionality that your application requires. Use a DataSet to do the following:

Cache data locally in your application so that you can manipulate it. If you only need to read the results of a query, the DataReader is the better choice. Remote data between tiers or from an XML Web service. Interact with data dynamically such as binding to a Windows Forms control or combining and relating data from multiple sources. Perform extensive processing on data without requiring an open connection to the data source, which frees the connection to be used by other clients.

If you do not require the functionality provided by the DataSet, you can improve the performance of your application by using the DataReader to return your data in a forward-only, read-only manner. Although the DataAdapter uses the DataReader to fill the contents of a DataSet, by using the DataReader, you can boost performance because you will save memory that would be consumed by the DataSet, and avoid the processing that is required to create and fill the contents of the DataSet

Lab Task:
Create a class Student having following data members and member methods:
rollNo, name, dateOfBirth, phoneNo, address Input() // to take the input from user ToString() // override this method to create and return string of all the data members

Create a class StudentDAL having following methods: RetrieveAll()


// this will read all students and return List of student objects

UpdateRecord(Student st)
//take the roll number of incoming student find it in database if exists the update existing information with the information coming in st object.

InsertNewRecord(Student st)
// Insert new record into the database

DeleteRecord( int rollNum)


// Delete record of the student matching the incoming roll number

RetrieveAllUsingDataSet()
// this will read all students and return DataSet

UpdateRecordUsingDataSet(Student st)
//take the roll number of incoming student find it in database if exists the update existing information with the information coming in st object.

InsertNewRecordUsingDataSet(Student st)
// Insert new record into the dataset first and then use the update method to reflect the changes in database.

DeleteRecordUsingDataSet( int rollNum)


// Delete record of the student matching the incoming roll number

Main()
Insert record of 5 students in the database. Retrieve all records from the database using RetrieveAll() and display them using ToString() Take input of student and update it using UpdateRecord() Again retrieve all records from the database and display them using ToString() of student object to see whether it is successfully updated or not. Insert new record using InsertNewRecord(). Again Retrieve all records from the database and display them using ToString() of student object to check whether it is successfully inserted or not. Lastly, call the DeleteRecord() to delete student.

Once, you have completed above steps, Now repeat the same steps using disconnected model as described below. Retrieve all records from the database using RetrieveAllUsingDataSet () and display them. Take roll number as input and update student record using UpdateRecordUsingDataSet () Again retrieve all records from the database and display them to see whether it is successfully updated or not. Insert new record using InsertNewRecordUsingDataSet(). Again Retrieve all records from the database and display them to check whether it is successfully inserted or not. Lastly, call the DeleteRecordUsingDataSet() to delete student.

To complete this lab, you can take help from the examples posted on piazza. To see the connection strings for particular database, check out the following site.

http://www.connectionstrings.com/ Note: Use Parameterized queries to prevent SQL Injection.

Das könnte Ihnen auch gefallen