Sunday, 15 June 2014

Wrong date format C#, Oracle -



Wrong date format C#, Oracle -

i'm trying date in right format(dd/mm/yyyy). @ moment in format: mm-dd-yyyy hh24:mi:ss when alter dd/mm/yyyy, works in database(oracle). run in app exception: indexoutofrange @ :

this.infolist9.add(dr["start_rcv_datetime"].tostring());

please see code below.

public list<string> infolist = new list<string>(); private void populatelbldate() { conn.open(); string query; query = "select to_char(dg.start_rcv_datetime,'dd/mm/yyyy') dc_pallet dp, dc_pallet_stock dps , dc_grv dg , sku s ,prod_size ps,colour c ,purch_order_carton_sku pocs , dc_crane_instruc dci dps.pallet_id_no = '" + palletid.tostring() + "' , dp.pallet_id_no = dps.pallet_id_no , dg.dc_grv_id_no = dps.dc_grv_id_no , dg.order_no = dps.order_no , dg.company_id_no = dps.company_id_no , s.company_id_no = dps.company_id_no , s.company_id_no = dg.company_id_no , dps.company_id_no = c.company_id_no , dps.company_id_no = ps.company_id_no , s.prod_size_id_no = ps.prod_size_id_no , s.colour_id_no = c.colour_id_no , dps.company_id_no = ps.company_id_no , pocs.order_no = dps.order_no , pocs.carton_code = dps.carton_code , pocs.company_id_no = dps.company_id_no , pocs.sku_id_no = s.sku_id_no , dci.pallet_id_no(+) = dp.pallet_id_no"; oraclecommand cmd = new oraclecommand(query, conn); oracledatareader dr = cmd.executereader(); while (dr.read()) { this.infolist.add(dr["start_rcv_datetime"].tostring()); } dr.close(); conn.close(); } private void frminfo_load(object sender, eventargs e) { populatelbldate(); lbl1.text = this.infolist[0]; }

then have prev , next button well...

your indexoutofrange exception suggests immediate problem result set doesn't contain column of start_rcv_datetime - presumably because of to_char conversion.

don't deal strings @ database side @ all. fetch value datetime, , format @ client in whatever want to.

use dr.getdatetime fetch value, having removed to_char part query:

query = "select dg.start_rcv_datetime ..."; using (oraclecommand cmd = new oraclecommand(query, conn)) { using (oracledatareader dr = cmd.executereader()) { int datecolumn = dr.getordinal("start_rcv_datetime"); while (dr.read()) { datetime date = dr.getdatetime(0); // or whatever - consider cultural implications string text = date.tostring("dd/mm/yyyy"); infolist.add(text); } } }

(note using statements - should create sure clean database-related resources.)

c# oracle

No comments:

Post a Comment