c# - Converting Dataset to IList -


this question has answer here:

i using sqlhelper execute stored procedure in db.

in namespace called constants defined this

public class showinstitutes {    public string institutename { get; set; }    public string institutecity { get; set; }    public int instituteid { get; set; } } 

in dal layer trying execute stored proc , results in ilist format

public ilist<showinstitutes> showinstitutes(int instituteid) {    return sqlhelper.executedataset(dbconnection, "usp_spname"); } 

i getting following error:

cannot implicitly convert type 'system.data.dataset' 'system.collections.generic.ilist<>

you can converting dataset result ilist this.

public ilist<showinstitutes> showinstitutes(int instituteid) {     var datatable = sqlhelper.executedataset(dbconnection, "usp_spname");     var sourcelists = new list<showinstitutes>();     (var index = 0; index < datatable.rows.count; index++)     {         sourcelists.add(new showinstitutes         {             institutename = convert.tostring(datatable.rows[index]["columnname"], cultureinfo.invariantculture),             institutecity = convert.tostring(datatable.rows[index]["columnname"], cultureinfo.invariantculture),             instituteid = convert.toint32(datatable.rows[index]["columnname"], cultureinfo.invariantculture)         });     }     return sourcelists; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -