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> <strong>Caché</strong> ADO <strong>Provider</strong> ClassesCacheDataReader reader = Command.ExecuteReader();while (reader.Read()) {Display.WriteLine(reader[reader.GetOrdinal("ID")] + "\t"+ reader[reader.GetOrdinal("Name")] + "\r\n\t"+ reader[reader.GetOrdinal("Home_City")] + " "+ reader[reader.GetOrdinal("Home_State")] + "\r\n");};The same report could be generated using column numbers instead of names. Since CacheDataReaderobjects can only read <strong>for</strong>ward, <strong>the</strong> only way to return to beginning of <strong>the</strong> data stream is to close <strong>the</strong>reader and reopen it by executing <strong>the</strong> query again.reader.Close();reader = Command.ExecuteReader();while (reader.Read()) {Display.WriteLine(reader[0] + "\t"+ reader[4] + "\r\n\t"+ reader[7] + " "+ reader[8] + "\n");}For a working example, see <strong>the</strong> ADO_1_CommandReader() method in <strong>the</strong> bookdemos sample program(see The <strong>Caché</strong> .<strong>NET</strong> Sample Programs).4.3 <strong>Using</strong> SQL Queries with CacheParameterThe CacheParameter object is required <strong>for</strong> more complex SQL queries. The following example selectsdata from all rows where Name starts with a string specified by <strong>the</strong> CacheParameter value:string SQLtext ="SELECT ID, Name, DOB, SSN "+ "FROM Sample.Person "+ "WHERE Name %STARTSWITH ?"+ "ORDER BY Name";CacheCommand Command = new CacheCommand(SQLtext, CacheConnect);The parameter value is set to get all rows where Name starts with A, and <strong>the</strong> parameter is passed to <strong>the</strong>CacheCommand object:CacheParameter Name_param =new CacheParameter("Name_col", CacheDbType.NVarChar);Name_param.Value = "A";Command.Parameters.Add(Name_param);A CacheDataReader object can access <strong>the</strong> resulting data stream just as it did in <strong>the</strong> previous example:22 <strong>Using</strong> <strong>the</strong> <strong>Caché</strong> <strong>Managed</strong> <strong>Provider</strong> <strong>for</strong> .<strong>NET</strong>

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

Saved successfully!

Ooh no, something went wrong!