c# - Populate lists from database (SQLite) -
i'm trying fill 2 lists informations on database sqlite.
public class investor // list { public int iid { get; set; } public string iname { get; set; } public string idisplayname { get; set; } public string iarea { get; set; } } public class area // list { public int aid { get; set; } public string aname { get; set; } public string adisplayname { get; set; } }
and
public class training : monobehaviour { public list<investor> investor() { var listofinvestor = new list<investor>(); string conn = "uri=file:" + application.datapath + "/db_01.s3db"; idbconnection dbconn; dbconn = (idbconnection) new sqliteconnection(conn); dbconn.open(); idbcommand dbcmd = dbconn.createcommand(); string sqlquery = "select * "+" investor; select * "+" area;"; dbcmd.commandtext = sqlquery; idatareader reader = dbcmd.executereader(); while(reader.read()) { var investor = new investor(); investor.iid = convert.toint32(reader["i_id"]); investor.iname = reader["i_name"].tostring(); investor.idisplayname = reader["i_display_name"].tostring(); investor.iarea = reader["i_area"].tostring(); listofinvestor.add(investor); } reader.close(); reader = null; dbcmd.dispose(); dbcmd = null; dbconn.close(); dbconn = null; return listofinvestor; }
i can second 1 fill, mean open twice db , call public list.
public list<area> area(){}
it's way ?
or maybe there way public list<string>[] loaddata() ?{}
you can advance second result after doing things. recommend use of using statements.
var listofinvestor = new list<investor>(); string conn = "uri=file:" + application.datapath + "/db_01.s3db"; using (var dbconnection = (idbconnection)new sqlliteconnection(conn)) using (var dbcmd = dbconnection.createcommand()) { dbconnection.open(); string sqlquery = "select * " + " investor; select * " + " area;"; dbcmd.commandtext = sqlquery; idatareader reader = dbcmd.executereader(); //read first result set while (reader.read()) { var investor = new investor(); investor.iid = convert.toint32(reader["i_id"]); investor.iname = reader["i_name"].tostring(); investor.idisplayname = reader["i_display_name"].tostring(); investor.iarea = reader["i_area"].tostring(); listofinvestor.add(investor); } //repeat other result set reader.nextresult(); while (reader.read()) { //do areas stuff here } }
Comments
Post a Comment