Vyoms OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Bookmark and Share Rss Feeds

Using OLEDB in ADO.NET with COBOL | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Sponsored Ads
Hot Jobs
Fresher Jobs
Experienced Jobs
Government Jobs
Walkin Jobs
Placement Section
Company Profiles
Interview Questions
Placement Papers
Resources @ VYOMS
Companies In India
Consultants In India
Colleges In India
Exams In India
Latest Results
Notifications In India
Call Centers In India
Training Institutes In India
Job Communities In India
Courses In India
Jobs by Keyskills
Jobs by Functional Areas
Learn @ VYOMS
GATE Preparation
GRE Preparation
GMAT Preparation
IAS Preparation
SAP Preparation
Testing Preparation
MBA Preparation
News @ VYOMS
Freshers News
Job Articles
Latest News
India News Network
Interview Ebook
Get 30,000+ Interview Questions & Answers in an eBook.
Interview Success Kit - Get Success in Job Interviews
  • 30,000+ Interview Questions
  • Most Questions Answered
  • 5 FREE Bonuses
  • Free Upgrades

VYOMS TOP EMPLOYERS

Wipro Technologies
Tata Consultancy Services
Accenture
IBM
Satyam
Genpact
Cognizant Technologies

Home » Articles » Using OLEDB in ADO.NET with COBOL

Using OLEDB in ADO.NET with COBOL








Article Posted On Date : Monday, March 26, 2012


Using OLEDB in ADO.NET with COBOL
Advertisements

Overview

In a previous article ("Data Access with ADO.NET", dated November 4, 2002) we discussed the use of the SqlClient class to access data in ADO.NET. The SqlClient class was created by Microsoft and is used primarily to access a SQL Server database. What about other databases? How would you access them? The answer is OleDB! Microsoft has provided a Framework to enable you to access other databases as well as SQL Server.

Through the use of OleDB you can access other databases that are .NET compliant. This is a major point to make here. The database MUST be .NET enabled for OleDB to work in .NET. One database we have been seeing quite a bit of interest in is Pervasive SQL. The latest version of this database, V8, is fully .NET enabled and we will utilize it in our example today.

I have installed the PervasiveV8 SDK and the Workgroup data engine. Both of these can be downloaded from the Pervasive Developer Zone (http://www.pervasive.com/developerZone/ ) and are free for development purposes. The sample we will be using a simple Console Application written in NetCOBOL that will access the DemoData database and the Person table specifically, displaying the data to the console. The version utilized returns 1500 rows.

Let's begin!

Ole!

We will be using the Ole class within the .NET Framework. The full Namespace specification can be found by performing a search in the Help system for System.Data.Oledb. ( I would recommend taking a few minutes and browsing through the online help files for OleDB. Microsoft has done a great job at providing good background and detail information) As with all of the Framework classes Microsoft has created a very extensive Namespace with many subclasses to assist you in developing your applications. Our application will be a basic connect, issue a command, read the data and handle any exceptions that occur. For this purpose we will utilize the following classes: OleDbConnection, OleDbCommand, OleDbDataReader, and OleDbException.

First Steps

Prior to beginning our Ole process we need to do some housework. We need to create references in our Repository to the Classes we mentioned above so we can access their methods and properties. To accomplish this we create four entries in the Repository, one for each of the aforementioned classes:

Notice the first four lines in the Repository reference the four Ole classes we are going to be using in our example. On the fifth line there is a Property statement. Within the OleDbException class their is a specific property we will be referencing and that is the Message. This property will contain a message whenever an exception is thrown in the OleDb namespace. "Great!" you may say, "So it gives me a message. Now what do I do with it?" Well every good COBOL programmer codes for exceptions and handles them accordingly, right? We're no exception (no pun intended) and have created a Declaratives section to handle any exceptions that occur.

The Declarative section is called any time an exception is generated. The Exception-Object is identified and an instance created (myException). Next the message is obtained from the instance, converted to a string and displayed on the console. A prompt has been added to halt execution of the application until the operator has responded.

In the Working-Storage Section we have created instance objects for each of the classes to be used as well as some other variables to receive the data and display it to the console. The Working-Storage Section will not be reviewed in more detail as it is pretty self-explanatory.

Now we can start on our four segments!

Connection (OleDbConnection)

The first item that has to be addressed is connecting to a database. Each database provider will have their own connection string and you will need to review the providers documentation in order to create a connection string in the proper format. The information necessary to connect to the Pervasive V8 database was located in the Pervasive SQL V8 SDK, Programmers Guide, ADO OLE/DB Programming, Connecting to a database using the OLE DB Provider. The connection was made an opened with the following lines of code:

The first line of code creates a new connection object (CONNECTIONOBJ) with the parameter specified in the USING phrase. This is where you need to be sure you have the proper connection string and syntax for the database you are connecting to. This is where it all starts. If you can't connect, you can't proceed. The second line of code invokes, or calls, the OPEN method of the connection class and establishes connectivity with the database.

Retrieve the Data (OleDbCommand)

Now we have to decide what we are going to retrieve. For our example we want to display the first and last name of the person, their email address and their date of birth. We first researched the database to obtain the proper names for the columns. The logic used to retrieve the data can best be described as 1. Set the criteria, 2. Create the command, and 3. Execute the command. The coding for doing this looks like the following

The first line of code establishes what we are going to select from the database. We are using a variable called MY-STRING to hold the selection because it made the code easier to read and follow. Another important point to consider is you can use the code as a template to create a dynamic selection method that can be called by other modules. By permitting your users to select options on another form you can pass in a selection string and then have it execute and return the data.

The second line of code creates a new command object, OLECOMMANDOBJ, that contains the command to execute. You have to create a new command object prior to execution, you can not merely execute the command. The third line of code calls the ExecuteReader method, which uses the command object and actually creates a data set that contains your data.

Read/Display the data (OleDbDataReader)

Outstanding! You've got data! Now what? Now we have to access the data in the DataReader object and display it on the screen. To accomplish this we will use the GetString method of the DataReader object (this is why it's a good idea to review the Namespaces and classes to see what it available to you before you begin coding). The following code will loop through accessing the datareader object and returning any data:

The first line of code checks to see if we have any data to process. It will set the variable MY-BOOLEAN to a binary "1" (true) if there is data to process, or binary "0" (false) if there is no data to process. The PERFORM loop will use MY-BOOLEAN to determine when to stop processing. The first four lines of code within the PERFORM loop read the data and place it into WORKING-STORAGE variables. The DATAREADEROBJ returns one column at a time identified by the USING phrase and has an offset of zero. The date of birth is a DateTime data type within Pervasive and thus has to be converted to a string before it can be displayed. This is done by first retrieving it in it's native format into a DateTime variable. This variable then invokes its ToString method to convert the data to a displayable format. While there may be other ways in which to display the data, I find it more acceptable to first retrieve the data to a comparable format and then convert the data via that data types methods. Finally we add one to a counter, display the data to the screen and check to see if we have any more data to retrieve.

If we have no other data to retrieve we close the connection, prompt for input from the user and exit the application. These steps can be reviewed in the attached code sample.

Wrap-up

Accessing databases within .NET other than SQL Server is very similar to the manner you use to access SQL Server. I realize that sounds funny but it's true. In accessing SQL Server via the SQLCLIENT namespace and other databases via the OLEDB namespace you perform the same steps:

    Establish the connection: Use the SqlConnection or OleDbConnection objects
    Create the command: Use the SqlCommand or OleDbCommand objects
    Read the data: Use the SqlDataReader or OleDbDataReader objects

The process is the same, the classes/methods are similar and the result is the same: Easy access to data. Hats off to Microsoft for providing a stream-lined data access methodology for not only their database but for others as well.






Sponsored Ads



Interview Questions
HR Interview Questions
Testing Interview Questions
SAP Interview Questions
Business Intelligence Interview Questions
Call Center Interview Questions

Databases

Clipper Interview Questions
DBA Interview Questions
Firebird Interview Questions
Hierarchical Interview Questions
Informix Interview Questions
Microsoft Access Interview Questions
MS SqlServer Interview Questions
MYSQL Interview Questions
Network Interview Questions
Object Relational Interview Questions
PL/SQL Interview Questions
PostgreSQL Interview Questions
Progress Interview Questions
Relational Interview Questions
SQL Interview Questions
SQL Server Interview Questions
Stored Procedures Interview Questions
Sybase Interview Questions
Teradata Interview Questions

Microsof Technologies

.Net Database Interview Questions
.Net Deployement Interview Questions
ADO.NET Interview Questions
ADO.NET 2.0 Interview Questions
Architecture Interview Questions
ASP Interview Questions
ASP.NET Interview Questions
ASP.NET 2.0 Interview Questions
C# Interview Questions
Csharp Interview Questions
DataGrid Interview Questions
DotNet Interview Questions
Microsoft Basics Interview Questions
Microsoft.NET Interview Questions
Microsoft.NET 2.0 Interview Questions
Share Point Interview Questions
Silverlight Interview Questions
VB.NET Interview Questions
VC++ Interview Questions
Visual Basic Interview Questions

Java / J2EE

Applet Interview Questions
Core Java Interview Questions
Eclipse Interview Questions
EJB Interview Questions
Hibernate Interview Questions
J2ME Interview Questions
J2SE Interview Questions
Java Interview Questions
Java Beans Interview Questions
Java Patterns Interview Questions
Java Security Interview Questions
Java Swing Interview Questions
JBOSS Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSF Interview Questions
JSP Interview Questions
RMI Interview Questions
Servlet Interview Questions
Socket Programming Interview Questions
Springs Interview Questions
Struts Interview Questions
Web Sphere Interview Questions

Programming Languages

C Interview Questions
C++ Interview Questions
CGI Interview Questions
Delphi Interview Questions
Fortran Interview Questions
ILU Interview Questions
LISP Interview Questions
Pascal Interview Questions
Perl Interview Questions
PHP Interview Questions
Ruby Interview Questions
Signature Interview Questions
UML Interview Questions
VBA Interview Questions
Windows Interview Questions
Mainframe Interview Questions


Copyright © 2001-2024 Vyoms.com. All Rights Reserved. Home | About Us | Advertise With Vyoms.com | Jobs | Contact Us | Feedback | Link to Us | Privacy Policy | Terms & Conditions
Placement Papers | Get Your Free Website | IAS Preparation | C++ Interview Questions | C Interview Questions | Report a Bug | Romantic Shayari | CAT 2024

Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |


Copyright ©2001-2024 Vyoms.com, All Rights Reserved.
Disclaimer: VYOMS.com has taken all reasonable steps to ensure that information on this site is authentic. Applicants are advised to research bonafides of advertisers independently. VYOMS.com shall not have any responsibility in this regard.