c# - Generic list not being populated by db -
i'm trying populate generic collection having problems. i'm trying populate mybookings, supposed store list. methods below should fill mybookings correct list reason when count result (int c), i'm getting return of 0. can see i'm doing wrong?
// .cs
public partial class _default : system.web.ui.page { iclean.bookings mybookings = new iclean.bookings(); iclean.booking mybooking = new iclean.booking(); iclean.controller mycontroller = new iclean.controller(); listitem li = new listitem(); protected void page_load(object sender, eventargs e) { currentfname.text = profile.firstname; currentuname.text = profile.username; currentlname.text = profile.lastname; mybookings.allbookings = this.getbookings(); int c = mybookings.allbookings.count(); name.text = c.tostring(); address.text = mybooking.address; phone.text = mybooking.phone; date.text = mybooking.duedate.tostring(); comments.text = mybooking.comments; } public list<iclean.booking> getbookings() { list<iclean.booking> bookings = new list<iclean.booking>(); arraylist records = this.select("bookings", ""); (int = 0; < records.count; i++) { iclean.booking tempbooking = new iclean.booking(); hashtable row = (hashtable)records[i]; tempbooking.id = convert.toint32(row["id"]); tempbooking.name = convert.tostring(row["clientname"]); tempbooking.address = convert.tostring(row["clientaddress"]); tempbooking.phone = convert.tostring(row["clientphone"]); tempbooking.duedate = convert.todatetime(row["bookingdate"]); tempbooking.completed = convert.toboolean(row["completed"]); tempbooking.paid = convert.toboolean(row["paid"]); tempbooking.cancelled = convert.toboolean(row["cancelled"]); tempbooking.reasoncancelled = convert.tostring(row["reasoncancelled"]); tempbooking.contractorpaid = convert.toboolean(row["contractorpaid"]); tempbooking.comments = convert.tostring(row["comments"]); tempbooking.windows = convert.toboolean(row["windows"]); tempbooking.gardening = convert.toboolean(row["gardening"]); tempbooking.indoorcleaning = convert.toboolean(row["indoorcleaning"]); bookings.add(tempbooking); } return bookings; } public arraylist select(string table, string conditions) { // create hosue records. arraylist records = new arraylist(); try { // open connection. oledbconnection myconnection = new oledbconnection(this.getconnectionstring()); myconnection.open(); // generate sql string sql = "select * " + table; if (conditions != "") { sql += " " + conditions; } // console.writeline("select sql: " + sql); // in case need debug // run sql oledbcommand mycommand = new oledbcommand(sql, myconnection); oledbdatareader myreader = mycommand.executereader(); // go through rows returned ... while (myreader.read()) { // ... create hashtable keep columns in, ... hashtable row = new hashtable(); // ... add fields ... (int = 0; < myreader.fieldcount; i++) { row.add(myreader.getname(i), myreader[i]); } // ... , store row. records.add(row); } // make sure close connection myconnection.close(); } catch (exception e) { console.writeline(e.message); } return records; } public string getconnectionstring() { string connectionstring = "provider=microsoft.ace.oledb.12.0;data source=iqquotes.accdb;"; return connectionstring; } }
just guess, try this:
public list<iclean.booking> getbookings() { list<iclean.booking> bookings = new list<iclean.booking>(); arraylist records = this.select("bookings", ""); iclean.booking tempbooking = new iclean.booking(); (int = 0; < records.count; i++) { tempbooking = new iclean.booking(); hashtable row = (hashtable)records[i]; tempbooking.id = convert.toint32(row["id"]); tempbooking.name = convert.tostring(row["clientname"]); tempbooking.address = convert.tostring(row["clientaddress"]); tempbooking.phone = convert.tostring(row["clientphone"]); tempbooking.duedate = convert.todatetime(row["bookingdate"]); tempbooking.completed = convert.toboolean(row["completed"]); tempbooking.paid = convert.toboolean(row["paid"]); tempbooking.cancelled = convert.toboolean(row["cancelled"]); tempbooking.reasoncancelled = convert.tostring(row["reasoncancelled"]); tempbooking.contractorpaid = convert.toboolean(row["contractorpaid"]); tempbooking.comments = convert.tostring(row["comments"]); tempbooking.windows = convert.toboolean(row["windows"]); tempbooking.gardening = convert.toboolean(row["gardening"]); tempbooking.indoorcleaning = convert.toboolean(row["indoorcleaning"]); bookings.add(tempbooking); } return bookings; }
Comments
Post a Comment