to_date function

  • Thread starter Thread starter gane kol
  • Start date Start date
gane said:
Hi

when i try to use to_date function in C# codebehind, i am getting to_date
doesnt exist in class or namespace error.

i am trying to use something similar to
INSERT INTO OracleTypesTable VALUES ( 'test', 2, to_date('2000-01-11
12:54:01','yyyy-mm-dd hh24:mi:ss'), '0001020304' )";

ref link:
http://msdn.microsoft.com/library/d...ataoracleclientoracledatareaderclasstopic.asp

i am using System.data.oracleclient

- Ganesh
any ideas?

that to_date function is Oracle sql, not C#. You might want to try
DateTime.Parse or DateTime.ParseExact.
 
But if you see the microsoft example,
they have used the to_date in c# code
---------------------------------------------
public void Setup(string connectionString)
{
OracleConnection conn = new OracleConnection(connectionString);
try
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText ="CREATE TABLE OracleTypesTable (MyVarchar2
varchar2(3000),MyNumber number(28,4) PRIMARY KEY ,MyDate date, MyRaw
raw(255))";
cmd.ExecuteNonQuery();
cmd.CommandText ="INSERT INTO OracleTypesTable VALUES ( 'test', 2,
to_date('2000-01-11 12:54:01','yyyy-mm-dd hh24:mi:ss'), '0001020304' )";
cmd.ExecuteNonQuery();
cmd.CommandText="SELECT * FROM OracleTypesTable";
}
catch(Exception)
{
}
finally
{
conn.Close();
}
}
--------------------------------------------------
 
No they haven't, the double quoted string starting after CommandText
contains the to_date oracle functon, so the to_date isn't a c# function,
it's passed to the db to execute.
 
That is because they have the entire query inside a string so C# does not
process it at all. It is possible that you do not and therefore C# is
trying to process it. Make sure your to_date is within the double quotes.
That way it is simply passed to the database for processing.
 
Back
Top