尝试使用WPF从Oracle数据库中选择记录时遇到问题。 我收到此错误:ORA-01830(日期格式图片在转换整个输入字符串之前结束 原因)
我的代码:
OracleDataReader dr;
OracleCommand cmd = new OracleCommand();
using (OracleConnection cn = new OracleConnection() { ConnectionString = "DATA SOURCE=*****:1521/ORCL;PASSWORD=*****;PERSIST SECURITY INFO=True;USER ID=*****" })
{
cn.Open();
// DateTime dt = Convert.ToDateTime(from_datePicker.Text);
OracleDataAdapter da = new OracleDataAdapter("Select B_NO,R_CLIENT_NAME,ENG_NAME,USER_NAME,R_ADDRESS,R_WORK_DATE,B_DATE,B_YEAR,B_WP_NAME,I_NAME,I_NO,BI_Q,I_CONTSR_TYPE_DESCR,R_PLACE_DESCR from VW_CI_REP_ITEMS_RESERV where R_WORK_DATE = '" + from_datePicker.SelectedDate + "'", cn);
DataSet ds2 = new DataSet();
da.Fill(ds2, "VW_CI_REP_ITEMS_RESERV");
DeltaInvoices_Grid.ItemsSource = ds2.Tables["VW_CI_REP_ITEMS_RESERV"].DefaultView;
}
GridCount_txt.Text = DeltaInvoices_Grid.Items.Count.ToString();
答案 0 :(得分:0)
遇到ORA-01830错误时,将出现以下错误消息:
ORA-01830:日期格式图片在转换整个输入字符串之前结束 原因 您尝试输入日期值,但是输入的日期与日期格式不匹配。
我认为您应该像这样将传递给oracle数据适配器的“日期”字段转换为:
TO_DATE(from_datePicker.SelectedDate, 'dd-mon-yyyy hh:mi PM')
或您已将此字段保存在数据库中的任何其他格式。
答案 1 :(得分:0)
尝试
OracleDataReader dr;
using (OracleConnection cn = new OracleConnection() { ConnectionString = "DATA SOURCE=*****:1521/ORCL;PASSWORD=*****;PERSIST SECURITY INFO=True;USER ID=*****" })
{
cn.Open();
var sql =
"Select B_NO,R_CLIENT_NAME,ENG_NAME,USER_NAME,R_ADDRESS,R_WORK_DATE,B_DATE,B_YEAR,B_WP_NAME,I_NAME,I_NO,BI_Q,I_CONTSR_TYPE_DESCR,R_PLACE_DESCR from VW_CI_REP_ITEMS_RESERV where R_WORK_DATE = :fromDatePicker";
OracleCommand cmd = new OracleCommand(sql, cn);
var parameter = new OracleParameter("fromDatePicker", OracleDbType.Date) {
Value = Convert.ToDateTime(from_datePicker.Text),
};
cmd.Parameters.Add(parameter);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds2 = new DataSet();
da.Fill(ds2, "VW_CI_REP_ITEMS_RESERV");
DeltaInvoices_Grid.ItemsSource = ds2.Tables["VW_CI_REP_ITEMS_RESERV"].DefaultView;
}
GridCount_txt.Text = DeltaInvoices_Grid.Items.Count.ToString();