CSharp examples for Database:ODBC
Run Select Statement using OdbcCommand
using System.Data.Odbc; using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w w w .ja va2 s. com public class Main{ internal static Dictionary<string, double> GetSymbolPrice() { Dictionary<string, double> symbolPriceList = new Dictionary<string, double>(); OdbcConnection con = new OdbcConnection(Constants.MyConString); try { OdbcCommand com = new OdbcCommand("SELECT DISTINCT symbol, CLOSE,date FROM symbolshistorical WHERE DATE=(SELECT DATE FROM historicaldates WHERE DateType='" + Constants.P + "')", con); con.Open(); OdbcDataReader dr = com.ExecuteReader(); while (dr.Read()) { string symbol = dr.GetString(0); double price = Double.Parse(dr.GetString(1)); DateTime date = DateTime.Parse(dr.GetString(2)); if (!symbolPriceList.ContainsKey(symbol)) { symbolPriceList.Add(symbol, price); } else { log.Warn("Duplicate data for symbol '" + symbol + "' in date " + date); } } dr.Close(); } catch (Exception ex) { log.Error(ex); } finally { if (con != null) con.Close(); } return symbolPriceList; } }