private void button9_Click(object sender, EventArgs e) { string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;"; string _result; try { OracleConnection _connObj = new OracleConnection(); _connObj.ConnectionString = _connstring; _connObj.Open(); OracleGlobalization info = OracleGlobalization.GetClientInfo(); info.Territory = "Sweden"; info.Language = "Swedish"; OracleGlobalization.SetThreadInfo(info); _connObj.SetSessionInfo(info); OracleCommand _cmdObj = _connObj.CreateCommand(); _cmdObj.CommandText = "SELECT TO_CHAR(Price,'L99G999D99') PriceDefCurrency, TO_CHAR(Price,'U99G999D99') PriceDualCurrency, TO_CHAR(ExpiryDate,'DL') ExpiryDate FROM Products WHERE ID='E1'"; OracleDataReader _reader = _cmdObj.ExecuteReader(); if (_reader.HasRows) { if (_reader.Read()) { String _priceDefCurrency = _reader.GetString(_reader.GetOrdinal("PriceDefCurrency")); String _priceDualCurrency = _reader.GetString(_reader.GetOrdinal("PriceDualCurrency")); String _expiryDate = _reader.GetString(_reader.GetOrdinal("ExpiryDate")); _result = _priceDefCurrency + "\n" + _priceDualCurrency + "\n" + _expiryDate; MessageBox.Show(_result); } } _reader.Dispose(); _cmdObj.Dispose(); _connObj.Dispose(); _reader.Close(); _connObj.Close(); _reader = null; _connObj = null; _cmdObj = null; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button4_Click(object sender, EventArgs e) { string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;"; string _result; try { OracleConnection _connObj = new OracleConnection(); _connObj.ConnectionString = _connstring; _connObj.Open(); OracleGlobalization info = OracleGlobalization.GetClientInfo(); info.DateLanguage = "FINNISH"; info.DateFormat = "DD-MON-YYYY"; OracleGlobalization.SetThreadInfo(info); OracleCommand _cmdObj = _connObj.CreateCommand(); _cmdObj.CommandText = "SELECT ExpiryDate FROM Products ORDER BY ExpiryDate ASC"; OracleDataReader _reader = _cmdObj.ExecuteReader(); _result = "Results:"; if (_reader.HasRows) { while (_reader.Read()) { OracleDate _odate = _reader.GetOracleDate(_reader.GetOrdinal("ExpiryDate")); _result = _result + "\n" + _odate.ToString(); } } MessageBox.Show(_result); _reader.Dispose(); _cmdObj.Dispose(); _connObj.Dispose(); _reader.Close(); _connObj.Close(); _reader = null; _connObj = null; _cmdObj = null; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button7_Click(object sender, EventArgs e) { string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;"; try { OracleConnection _connObj = new OracleConnection(); _connObj.ConnectionString = _connstring; _connObj.Open(); OracleGlobalization info = OracleGlobalization.GetClientInfo(); info.Territory = "Hong Kong"; info.TimeZone = "Asia/Hong_Kong"; OracleGlobalization.SetThreadInfo(info); _connObj.SetSessionInfo(info); OracleCommand _cmdObj = _connObj.CreateCommand(); _cmdObj.CommandText = "SELECT LaunchDate AT LOCAL LaunchDateLocal FROM Products"; OracleDataReader _reader = _cmdObj.ExecuteReader(); if (_reader.HasRows) { if (_reader.Read()) { OracleTimeStampTZ _launchDate = _reader.GetOracleTimeStampTZ (_reader.GetOrdinal("LaunchDateLocal")); MessageBox.Show(_launchDate.ToString()); } } _reader.Dispose(); _cmdObj.Dispose(); _connObj.Dispose(); _reader.Close(); _connObj.Close(); _reader = null; _connObj = null; _cmdObj = null; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private bool SetGlobalizationParams() { try { // Get the default thread setting OracleGlobalization threadGlob = OracleGlobalization.GetThreadInfo(); //modify the NLS_LANGUAGE parameter AMERICAN_AMERICA threadGlob.Language = "AMERICAN"; // "THAI"; // modify the NLS_TERRITORY parameter threadGlob.Territory = "AMERICA"; // "THAILAND"; // modify the NLS_DATE_FORMAT parameter threadGlob.DateFormat = "Day:Dd Month yyyy";//"dd/MM/yyyy"; // set the modified NLS parameters for thread //Thread's NLS settings are used by any data retrieved //as .NET String type. OracleGlobalization.SetThreadInfo(threadGlob); //Get session's default NLS settings OracleGlobalization sessionGlob = this.Connection.GetSessionInfo(); // modify the NLS_TERRITORY parameter sessionGlob.Territory = "AMERICA";//"THAI"; // set the modified NLs parameters for session // Session's NLS settings are used by data retrieved using //TO_CHAR function used in SELECT statements. this.Connection.SetSessionInfo(sessionGlob); } catch (Exception e) { return(false); } return(true); }
/******************************************************************* * The method sets the NLS parameters for the current thread and session. * These NLS values will be used while retrieving and updating the data into * the database. ********************************************************************/ private bool setGlobalizationParams() { try { // Get the default thread setting OracleGlobalization threadGlob = OracleGlobalization.GetThreadInfo(); //modify the NLS_LANGUAGE parameter threadGlob.Language = Config.language; // modify the NLS_TERRITORY parameter threadGlob.Territory = Config.territory; // modify the NLS_DATE_FORMAT parameter threadGlob.DateFormat = Config.dateformat; // set the modified NLS parameters for thread //Thread's NLS settings are used by any data retrieved //as .NET String type. OracleGlobalization.SetThreadInfo(threadGlob); //Get session's default NLS settings OracleGlobalization sessionGlob = ConnectionManager.conn.GetSessionInfo(); // modify the NLS_TERRITORY parameter sessionGlob.Territory = Config.territory; // set the modified NLs parameters for session // Session's NLS settings are used by data retrieved using //TO_CHAR function used in SELECT statements. ConnectionManager.conn.SetSessionInfo(sessionGlob); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } return(true); }