Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Function to Create an ADO Connection

$
0
0

The recommended approach to access databases in Visual COBOL .NET is to use OpenESQL as Werner points out. This allows you to embed your SQL commands directly within the COBOL code using EXEC SQL statements.

You can also code directly to the native ADO.NET classes like your VB example shows by creating a connection object, calling its Open method, etc.

Your VB code above can be written in VC as follows:

      $set ilusing"System.Data.SqlClient"
      $set ilusing"System"
      $set ilusing"System.IO"
      $set ilusing"System.Collections"
       class-id adoconnect.LocalSQLDB.
       working-storage section.
       method-id GetConnection.
       procedure division returning myconnection as type SqlConnection.
           declare myConnStr as string = "Data Source=localhost\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True"
           set myconnection to new SqlConnection(myConnStr)
           goback.
       end method.
       end class.

For more information on this subject I would recommend that you read the section under Programming-->Data Access-->Database Access in the Help and to also watch the following:

Visual COBOL in a Nutshell: Using ADO.NET with Visual COBOL
Visual COBOL in a Nutshell OpenESQL Database Connections

Also watch the other videos for OpenESQL posted at the same location.


Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>