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

Visual COBOL equivalent to C# "Using" statement?

$
0
0

Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // + "c:\\Data\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Austin1\Documents\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        + "c:\\Users\\Austin1\\Documents\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                + "WHERE UnitPrice > ? "

                + "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\t{0}\t{1}\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 


Viewing all articles
Browse latest Browse all 4356

Trending Articles



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