c# - populate objectlistview using datatable list -
im work objectlistview , trouble populate data database list , here code
static internal list<birthday> getbirthdays() { if (birthday.alldata.count == 0) birthday.alldata = birthday.initializedata(); return birthday.alldata; } static private list<birthday> alldata = new list<birthday>(); static private list<birthday> initializedata() { koneksi con = new koneksi(); var qcmd = "select nm, sex, replace(hp, ' ', '') hp, datediff(year, left(tgllhr, 4), '2016') umur, alamat " + "from mcif " + "where right(tgllhr, 4) = 20160615"; con.sqlquery(qcmd); list<birthday> birthdaylist = new list<birthday>(); using (datatable dt = con.queryex()) { birthdaylist = (from datarow dr in dt.rows select new birthday() { nama = convert.tostring(dr["nm"]), sex = convert.tostring(dr["sex"]), hp = convert.tostring(dr["hp"]), umur = convert.toint32(dr["umur"]), alamat = convert.tostring(dr["alamat"]) }).tolist(); }
and connection
public class koneksi { private sqlconnection _con; private sqlcommand cmd; private sqldataadapter _da; private datatable _dt; public koneksi(string connectionstring=null) { var myini = new inifile("setting.ini"); string database = myini.read("set1", "database"); string userdb = myini.read("set2", "database"); string passdb = myini.read("set3", "database"); string locdb = myini.read("set4", "database"); _con = new sqlconnection(connectionstring??@"data source=" + locdb + ";initial catalog=" + database + "; user id=" + userdb + ";password=" + passdb + ""); _con.open(); } public void sqlquery(string querytext) { cmd = new sqlcommand(querytext, _con); } public datatable queryex() { _da = new sqldataadapter(cmd); _dt = new datatable(); _da.fill(_dt); return _dt; } }
this code in form :
private void initializedataolv() { this.flv.setobjects(birthday.getbirthdays()); }
i have try several example this olv still empty, still beginner using model list
Comments
Post a Comment