ado01Example_main.cs

TBD: Update GenDefines.txt with a $DESCRIPTION for this example.

using System;
/* Raima.Rdm is the system module that contains the ADO.NET
* data provider for RDM */
using Raima.Rdm;
/* EXAMPLE - Hello World for C# using ADO.NET */
/* Each time you run this example, a new record is created in the
* database, then all existing records are read from the database
* and printed.
*
* The following methods are illustrated:
* Raima.Rdm.RdmConnection:
* Close() Method
* CreateCommand() Method
* Open() Method
* RdmConnection() Constructor
* Raima.Rdm.RdmCommand:
* CommandText Property
* ExecuteNonQuery() Method
* ExecuteReader() Method
* Raima.Rdm.RdmDataReader:
* Item[int] Property
* Read() Method
*
* They are fully document in http://docs.raima.com/rdm/.
*
* For simplicity this example does not catch any thrown execptions
* but good programming practices would dictate that this occur in
* a full application.
*/
namespace HelloWorld_CS_ADO
{
class Program
{
static void CreateDatabase()
{
/* Attempt to create the database. If the database already exists
* this will fail and we simply ignore the failure for this sample. */
RdmConnection createConn = new RdmConnection("host=local");
createConn.Open();
RdmCommand createCmd = createConn.CreateCommand();
try
{
createCmd.CommandText = "CREATE DATABASE HelloWorld";
createCmd.ExecuteNonQuery();
createCmd.CommandText = "CREATE TABLE HelloTab (message CHAR(30))";
createCmd.ExecuteNonQuery();
createCmd.CommandText = "COMMIT";
createCmd.ExecuteNonQuery();
}
catch (Exception)
{
}
createConn.Close();
}
static void Main(string[] args)
{
CreateDatabase();
/* Create the connection with a simple connection string */
RdmConnection conn = new RdmConnection("host=local;database=HelloWorld;openmode=Exclusive");
/* Open the connection to the database */
conn.Open();
/* Create a new command and set its text to insert a row */
RdmCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO HelloTab VALUES 'Hello World'";
/* Execute the command, inserting a row */
cmd.ExecuteNonQuery();
/* Scan through all the existing records and print out the data */
cmd.CommandText = "SELECT message FROM HelloTab";
RdmDataReader reader = cmd.ExecuteReader();
while (reader.Read())
Console.WriteLine(reader[0]);
conn.Close();
}
}
}