Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle date format -- data reader not recognizing to_char function
    primarykey
    data
    text
    <p>Basically just pulling a date out in YYYYMMDD and I can do this fine in a query analyzer but when I try to run this query in C# I keep getting a column not found error it also seems to have a hard time doing concatenation (but that isn't so much of a problem) so a little unsure of what is happening here..I really just want my to_char function to work. Ideas? Thanks!</p> <pre><code> string oradb = "user id=x;password=x;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)" +"(HOST=x)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=x)));"; OracleConnection conn = new OracleConnection(oradb); conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT to_char(ProblemDate, 'yyyymmdd'), data1, data2," +"data4, data5, data6" +" WHERE ( ProblemDate &gt;='03-oct-2011' ) " +"AND ( ProblemDate &lt;= '08-oct-2011' ) AND " +"( data1 in ( '3','5','6' ) )"; OracleDataReader dr = cmd.ExecuteReader(); string fileOut1 = Request.PhysicalApplicationPath; string fileOut = fileOut1 + "Text5.txt"; // Creates the file StreamWriter sw = new StreamWriter(fileOut); if (dr.HasRows) { while (dr.Read()) { string data1= (string)dr["data1"].ToString(); string data2 = (string)dr["data3"].ToString(); string data3 = (string)dr["data4"]; string data4 = (string)dr["data5"].ToString(); string data5 = (string)dr["data6"].ToString(); string ProblemDate = (string)dr["ProblemDate"].ToString(); //remove the comma char[] MyChar = { ',' }; sw.WriteLine(data1.PadRight(10) + data2.PadRight(5) + data3.TrimEnd(MyChar) + "000" + data4 + "000" + data5+ ProblemDate + " " + "N" ); Label1.Text = "File created successfully.&lt;br /&gt;"; Label1.Text += fileOut1; } // Closes the connenction. sw.Close(); conn.Close(); } else { Label1.Text = "No data written."; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload