13.07.2015 Views

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> TransactionsCacheDataReader reader = Command.ExecuteReader();while (reader.Read()) {Display.WriteLine(reader[reader.GetOrdinal("ID")] + "\t"+ reader[reader.GetOrdinal("Name")] + "\r\n\t"+ reader[reader.GetOrdinal("DOB")] + " "+ reader[reader.GetOrdinal("SSN")] + "\r\n");};For a working example, see <strong>the</strong> ADO_2_Parameter() method in <strong>the</strong> bookdemos sample program (seeThe <strong>Caché</strong> .<strong>NET</strong> Sample Programs).The CacheCommand, CacheParameter, and CacheDataReader classes are also used to execute a <strong>Caché</strong>Query method from a proxy object. See <strong>Using</strong> <strong>Caché</strong> Queries <strong>for</strong> details.4.4 <strong>Using</strong> TransactionsThe Transaction class is used to specify an SQL transaction (see Transaction Processing in <strong>the</strong> “Modifying<strong>the</strong> Database” chapter of <strong>Using</strong> <strong>Caché</strong> SQL <strong>for</strong> a overview of how to use transactions with<strong>Caché</strong>). In <strong>the</strong> following example, transaction Trans will fail and be rolled back if SSN is not unique.CacheTransaction Trans =CacheConnect.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);try {string SQLtext = "INSERT into Sample.Person(Name, SSN) Values(?,?)";CacheCommand Command = new CacheCommand(SQLtext, CacheConnect, Trans);CacheParameter Name_param =new CacheParameter("name", CacheDbType.NVarChar);Name_param.Value = "Rowe, Richard";Command.Parameters.Add(Name_param);CacheParameter SSN_param =new CacheParameter("ssn", CacheDbType.NVarChar);SSN_param.Value = "234-56-3454";Command.Parameters.Add(SSN_param);int rows = Command.ExecuteNonQuery();Trans.Commit();Display.WriteLine("Added record <strong>for</strong> " + SSN_param.Value.ToString());}catch (Exception eInsert) {Trans.Rollback();WriteErrorMessage("TransFail", eInsert);}For a working example, see <strong>the</strong> ADO_4_Transaction() method in <strong>the</strong> bookdemos sample program(see The <strong>Caché</strong> .<strong>NET</strong> Sample Programs).<strong>Using</strong> <strong>the</strong> <strong>Caché</strong> <strong>Managed</strong> <strong>Provider</strong> <strong>for</strong> .<strong>NET</strong> 23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!