Nonstop Database, HiRDB Version 9 UAP Development Guide
This example inserts data 1 to the ex table:
using System; using System.Data; using Hitachi.HiRDB; namespace test_C { class Sample { [STAThread] static void Main(string[] args) { // Create a Connection object HiRDBConnection cn = new HiRDBConnection("dsn=pc;"); // Connect to the database cn.Open(); // Create a Transaction object HiRDBTransaction tran; // Start of transaction tran = cn.BeginTransaction(IsolationLevel.ReadCommitted); ..1 // Create a Command object HiRDBCommand cm = new HiRDBCommand(); cm.Connection = cn; cm.Transaction = tran; try { // Insert data in the table cm.CommandText = "insert into ex values (1)"; cm.ExecuteNonQuery(); // Transaction was successful tran.Commit(); .........................................2 // Disconnect from the database cn.Close(); } catch (HiRDBException ex) { // Transaction failed tran.Rollback(); .......................................3 Console.WriteLine(ex); } catch (System.Exception ex) { // Transaction failed tran.Rollback(); .......................................3 Console.WriteLine(ex); } } } } |
Imports System Imports System.Data Imports Hitachi.HiRDB Module Module1 Sub Main() Dim cn As HiRDBConnection Dim tran As HiRDBTransaction Dim cm As HiRDBCommand ' Create a Connection object cn = New HiRDBConnection("dsn=pc;") ' Connect to the database cn.Open() ' Start a transaction tran = cn.BeginTransaction(IsolationLevel.ReadCommitted) .......1 ' Create a Command object cm = New HiRDBCommand() cm.Connection = cn cm.Transaction = tran Try ' Insert data in the table cm.CommandText = "insert into ex values (1)" cm.ExecuteNonQuery() ' Transaction is successful tran.Commit() ..............................................2 ' Disconnect from the database cn.Close() Catch ex As HiRDBException ' Transaction fails tran.Rollback() ............................................3 Console.WriteLine(ex) Catch ex As System.Exception ' Transaction fails tran.Rollback() ............................................3 Console.WriteLine(ex) End Try End Sub End Module |
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.