This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
dev:odbc:sample [2011/01/12 21:56] els |
— (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | {{page>:top_add&nofooter&noeditbtn}} | ||
| - | |||
| - | ====== Development: ODBC Interface ====== | ||
| - | |||
| - | [[dev:odbc:home|Overview]] | [[dev:odbc:datasources|ODBC Datasources]] | **[[dev:odbc:sample|Sample C# Program]]** | ||
| - | |||
| - | ---- | ||
| - | |||
| - | |||
| - | ===== Sample ODBC Program ===== | ||
| - | |||
| - | The following is a very simple C# program that shows a basic connection to an Omnidex Environment and simple query processing. | ||
| - | |||
| - | <code csharp> | ||
| - | using System; | ||
| - | using System.Collections.Generic; | ||
| - | using System.Linq; | ||
| - | using System.Text; | ||
| - | using System.Data.Odbc; | ||
| - | |||
| - | namespace OdxODBCSample | ||
| - | { | ||
| - | class OdxODBCSample | ||
| - | { | ||
| - | static void Main(string[] args) | ||
| - | { | ||
| - | Console.WriteLine("Omnidex Sample C# Program"); | ||
| - | // Have to use a USER DSN | ||
| - | string connString = @"[server1:7555]c:\class\simple.xml"; | ||
| - | string sqlselect = @"select NAME, PHONE from INDIVIDUALS"; | ||
| - | OdbcConnection conn = null; | ||
| - | OdbcDataReader reader = null; | ||
| - | try | ||
| - | { | ||
| - | // Open Connection | ||
| - | conn = new OdbcConnection(connString); | ||
| - | conn.Open(); | ||
| - | // | ||
| - | OdbcCommand cmd = new OdbcCommand(sqlselect, conn); | ||
| - | reader = cmd.ExecuteReader(); | ||
| - | // Display output header | ||
| - | Console.WriteLine("NAME\tPHONE\n"); | ||
| - | // Process the result set | ||
| - | while(reader.Read()) | ||
| - | { | ||
| - | Console.WriteLine( | ||
| - | "{0} | {1}" | ||
| - | , reader["NAME"].ToString().PadLeft(10) | ||
| - | , reader["PHONE"].ToString().PadLeft(10) | ||
| - | ); | ||
| - | } | ||
| - | } // try | ||
| - | catch (Exception e) | ||
| - | { | ||
| - | Console.WriteLine("Error: " + e); | ||
| - | } | ||
| - | } // end main | ||
| - | } // end class | ||
| - | } // end namespace | ||
| - | </code> | ||
| - | |||
| - | ===== ===== | ||
| - | |||
| - | **[[dev:odbc:datasources|Prev]]** | ||
| - | |||
| - | ====== Additional Resources ====== | ||
| - | |||
| - | See also: | ||
| - | |||
| - | {{page>:dev:see_also&nofooter&noeditbtn}} | ||
| - | |||
| - | {{page>:bottom_add&nofooter&noeditbtn}} | ||