RDM 14.2 provides an ADO .NET interface to allow an application to access RDM databases through ADO .NET. It means any application written in a .NET language supported in the CLR (Common Language Runtime) can access RDM databases.

The RDM ADO .NET interface is an ADO .NET Data Provider that provides the following classes, enumerations and delegates.




Basic ADO .NET Application Steps

You can build a simple ADO .NET (#C) application that works with an RDM database by taking the following steps.

  1. Instantiate the following class objects:
    1. A String object that defines your connection string. Use "host=local;database=HelloWorldDb" for this example.
    2. An RdmConnection object to handle your connection to the RDM database system. Pass in the connection string created above to the constructor.
    3. An RdmCommand object to handle the SQL statements executed against the RDM database.

    4. An RdmDataReader object to read data from the RDM database.

  2. Open the database:

    1. Call the RdmCommand object's Open method to open the database.

    2. If necessary, call the RdmCommand object's BeginTransaction method to start a transaction. The method returns an RdmTransaction object that an application can use later to commit or rollback the transaction.

  3. Prepare SQL statement execution

    1. Set the RdmCommand object's CommandText property to define the SQL statement you want to execute.

    2. If the SQL statement above contains parameter markers, instantiate an RdmParameter object for each of the parameter markers.

    3. Call the Add method for each RdmParameter object to bind an application variable to the parameter associated with the object.

  4. Execute the SQL statement

    1. If the SQL statement is not a query, call the RdmCommand object's ExecuteNonQuery method.

    2. If the SQL statement is a query, call the RdmCommand object's ExecuteReader method to retrieve a result set. The method returns an RdmDataReader object that an application can use to read the rows in the result set.

    3. If necessary, call the RdmTransaction object's Commit or Rollback method to commit or rollback the transaction.

  5. Close all the objects

    1. Call the RdmDataReader object's Close method if necessary.

    2. Call the RdmConnection object's Close method to close the application's connection to the RDM database.

Hello World!

If you follow the basic procedure listed above you can easily create a simple database where you insert some data and the retrieve the data to be displayed back out. This can be seen with the common Hello World example.

In the example below return codes are mostly ignored for simplicity. This will be OK because we know what the expected results are.

/***********************************************************************    HELLO WORLD ADO.NET**    ---------------**    This document describes the process to open a simple database, insert a record **    containing a text field, read the text field from database and print it out.**********************************************************************/using System;using Raima.Rdm;   /* The RDM ADO.NET API */using System.Data;namespace HelloWorldApplication{    class HelloWorld    {        static void Main()        {            // Setup connection and SQL query strings            string connectionString = "host=local;database=hello_worldADO";            string deleteString = "DELETE FROM hello_table";            string insertString = "INSERT INTO hello_table(f00) VALUES(?)";            string queryString = "SELECT * FROM hello_table";            // Create connection object to connect to the database            RdmConnection connection = new RdmConnection(connectionString);            // Create a command object to execute SQL statements            RdmCommand command = connection.CreateCommand();            // Create a transaction object to start and stop transactions            RdmTransaction rdmtrans = null;            // Create a reader object to read out data from the SQL query            RdmDataReader reader = null;            try            {                /* Open a connection to the database */                connection.Open();                // Start a transaction                rdmtrans = connection.BeginTransaction();                command.CommandText = deleteString;                // Execute the DELETE statement                command.ExecuteNonQuery();                // Execute the INSERT statement                command.CommandText = insertString;                // Set up the input parameter                RdmParameter parameter = new RdmParameter();                parameter.RdmType = RdmType.AnsiString;                parameter.Direction = ParameterDirection.Input;                parameter.Value = "Hello World!";                command.Parameters.Add(parameter);                // Execute the INSERT statement                command.ExecuteNonQuery();                command.Parameters.Clear();                // Commit the transaction                rdmtrans.Commit();                command.CommandText = queryString;                // Execute a select statement which should return results                reader = command.ExecuteReader();                // Read all of the results                while (reader.Read())                {                    // Print out each row of the select in a newline                    Console.WriteLine(reader.GetString(0));                }                // Close the reader since retrieved all rows                reader.Close();                // Close the connection                connection.Close();            }            catch (Exception ex)            {                Console.WriteLine(ex.Message);            }        }    }}