Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

15.8.2 Executing the SQL statement

This example creates a table named ex:

 
using System;
using Hitachi.HiRDB;
 
namespace test_C
{
    class Sample
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                // Create a Connection object
                HiRDBConnection cn = new HiRDBConnection("dsn=pc;");  ...1
 
                // Connect to the database
                cn.Open();
 
                // Create a Command object
                HiRDBCommand cm = new HiRDBCommand();
 
                // Create a table
                cm.Connection = cn;
                cm.CommandText = "create table ex (a int)";
                cm.ExecuteNonQuery();  ..................................1
 
                // Disconnect from the database
                cn.Close();
            }
            catch (HiRDBException ex)
            {
                Console.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
 

Explanation
  1. To execute an SQL statement, use the Execute method. Specify a string-type SQL statement as is in the CommandText property of HiRDBCommand. This method can execute most SQL statements. Special SQL statements such as commit cannot be executed by this method, as well as statements such as select that must receive a result set. To execute these SQL statements, use dedicated methods.