Thursday 4 August 2016

ADO.NET Connection Oriented Architecture


ADO.NET provides the following two models for accessing data from a Data Source:
  • Connection Oriented Architecture
  • Disconnected Oriented Architecture
In this article, I would brief about ADO.Net Connection oriented architecture. Open  VS 2012 >New Projects > Visual C#  >  Windows> Console Application. Add new class file and name it as ConnectionOriented and we would develop methods as shown below.
Include System.Data and System.Data.SqlClient namespaces.

In InsertMethod we would create a connection object and try to execute Insert statement using command with ExecuteNonQuery statement. Note the connection remain in open state till the command is execute and finally closed. ExecuteNonQuery is used for Insert update and delete kind of operations.

In SelectMethod, we perform select operation with sqlconnection and sqlcommand by passing command parameter and we perform ExecuteReader to fetch the data from DB.
In SPApproachMethod, we try to insert and select the product information using store procedure and we pass commandtype as storeprocedure. In all the methods, we open the sql connection and close it after the operation is performed.

Below is store procedure that is executed from application. 


In  program class, create an instance of ConnectionOriented class and perform the operations as shown below.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.