Points To Be Discussed: Execution Command Insertion Command Updation Command Deletion Command Select Command
Points To Be Discussed: Execution Command Insertion Command Updation Command Deletion Command Select Command
ADO.NET
Accessing Database with ADO.NET Execution Command Insertion Command Updation Command Deletion Command Select Command
ADO.NET
ost applications need data access at one point o! time. Data Access is ma"ing the application interact with a database# where all the data is stored. Di!!erent applications ha$e di!!erent re%uirements !or database access. C& uses ADO.NET(ActiveX Data Object) as its data access. ADO.NET is a set o! computer so!tware components that programmers can use to access data and data ser$ices. It is commonl' used b' programmers to access and modi!' data stored in relational database s'stems. such as icroso!t S() Ser$er# as well as data sources exposed through O)E D* and + ).
ADO.NET
ADO.NET pro$ides two ob,ects to manipulate data
-.
Data Set: ADO.NET uses the disconnected approach using the DataSet. The DataSet acts as a container. All the data coming !rom the database is dumped in the DataSet# to use and manipulate. The database is then later updated with the DataSet. DataSet consists o! DataTables. DataTables are similar to tables or relations in D* S. DataTables contain Data/ows and DataColumns.
ADO.NET
.. .NET Data Provider: pro$iders a$ailable0 There are two .NET data
-. The S() Ser$er .NET Data 1ro$ider .. The O)ED* .NET Data 1ro$ider
S() Ser$er .NET Data 1ro$ider classes are located in the System.Data.Sq ! ient namespace. O)ED* .NET Data 1ro$ider classes are located in System.Data.O"ED# namespace. These .NET pro$iders include the !onnection ob,ect# the !ommand ob,ect# the Data$eader and the DataAda%ter in their corresponding namespaces.
to a data source. The !ommand ob,ect enables access to database commands to return data# modi!' data# run stored procedures# and send or retrie$e parameter in!ormation. The Data$eader pro$ides a stream o! read2onl' and !orward2onl' data !rom the data source. DataAda%ter pro$ides the bridge between the DataSet ob,ect and the data source.
connection ob,ect establishes the connection !or the application with the database. The command ob,ect pro$ides direct execution o! the command to the database. I! the command returns more than a single $alue# the command ob,ect returns a Data/eader to pro$ide the data. Alternati$el'# the DataAdapter can be used to !ill the Dataset ob,ect. The database can be updated using the command ob,ect or the DataAdapter.
database. .NET pro$ides two t'pes o! Connection classes0 the S%lConnection ob,ect# and the OleDbConnection ob,ect. The Connection ob,ect contains all o! the in!ormation re%uired to open a connection to the database.
T'e
!ommand Object: The Command ob,ect is represented b' two corresponding classes0 S%lCommand and OleDbCommand. Command ob,ects are used to execute commands to a database across a data connection. Command ob,ects pro$ide three methods that are used to execute commands on the database0 E*ecuteNon+uery: Executes commands that ha$e no return $alues such as INSE/T# U1DATE or DE)ETE E*ecuteSca ar: /eturns a single $alue !rom a database %uer' E*ecute$eader: /eturns a result set b' wa' o! a Data/eader ob,ect
). ,. -.
onl'# read2onl'# connected stream recordset !rom a database. The S%lCommand.Execute/eader method returns a S%lData/eader ob,ect# and the OleDbCommand.Execute/eader method returns an OleDbData/eader ob,ect.
T'e DataAda%ter Object: The DataAdapter class is used either to !ill a
DataTable or DataSet with data !rom the database with it3s 4ill method. A!ter the memor'2resident data has been manipulated# the DataAdapter can commit the changes to the database b' calling the Update method. The DataAdapter pro$ides !our properties that represent database commands0
-. SelectCommand .. InsertCommand 5. DeleteCommand 6. UpdateCommand