基本上只是拉日期出YYYYMMDD,我可以在查詢分析器這樣做很好,但是當我嘗試運行在C#此查詢我不斷收到一列未找到錯誤它似乎也很難做拼接(但這不是一個問題),所以有點不確定這裏發生了什麼......我真的只想讓我的to_char函數工作。想法?謝謝!Oracle日期格式 - 數據讀取器不能識別TO_CHAR函數
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 >='03-oct-2011') "
+"AND (ProblemDate <= '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.<br />";
Label1.Text += fileOut1;
}
// Closes the connenction.
sw.Close();
conn.Close();
}
else
{
Label1.Text = "No data written.";
}
哦,哇。這是我沒有嘗試的唯一的事情。謝謝! – mtnwk
我一開始並沒有注意到這一點,但正如@Rajesh在他的回答中指出的那樣,沒有'FROM'子句,這也是一個問題。 :) – wweicker
@mtnwk這個答案(或另一個)解決了你的問題嗎?如果是這樣,請將相應的答案標記爲已接受。 – wweicker