mysql - how to store null values in listbox c# -
i'm developing windows store app , has many list boxes retrieve info database, here mysql database screenshot
after null value in database listboxes not filling info shown next screenshot
i want maintain null values empty in list box , store other details how can that
here c# code
private void button_view_click(object sender, routedeventargs e) { listb0.items.clear(); listb1.items.clear(); listb2.items.clear(); listb3.items.clear(); listb4.items.clear(); seek { string query = @"select * `bcasdb`.`tbl_results`;"; //this command class handle query , connection object. mysqlconnection conn = new mysqlconnection(bcasapp.datamodel.db_con.connection); mysqlcommand cmd = new mysqlcommand(query, conn); mysqldatareader myreader; conn.open(); myreader = cmd.executereader();// query executed , info saved database. while (myreader.read()) { listboxitem itm0 = new listboxitem(); itm0.content = myreader.getstring(0); this.listb0.items.add(itm0); listboxitem itm1 = new listboxitem(); itm1.content = myreader.getstring(1); this.listb1.items.add(itm1); listboxitem itm2 = new listboxitem(); itm2.content = myreader.getstring(2); this.listb2.items.add(itm2); listboxitem itm3 = new listboxitem(); itm3.content = myreader.getstring(3); this.listb3.items.add(itm3); listboxitem itm4 = new listboxitem(); itm4.content = myreader.getstring(4); this.listb4.items.add(itm4); } conn.close(); } grab (exception) { errormsgbox(); } }
if prefer work issue in code need check dbnull using dbnull method of datareader
listboxitem itm2 = new listboxitem(); itm2.content = myreader.isdbnull(2) ? "" : myreader.getstring(2); this.listb2.items.add(itm2);
of course of study pattern should applied other columns potentially null.
c# mysql listbox
No comments:
Post a Comment