Hello sir,
I want to convert a DataTable to IList in MVC using nHibernate
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Oct 30, 2012, 2:42 AM
Hi,
To convert datatable to Ilist you required one custom Model(POCO class).
Example :
public class testClass
{
public string Test1 { get; set; }
public string Test2 { get; set; }
public string Test3 { get; set; }
}
DataTable dTable = new DataTable();
dTable.Columns.Add("Test1");
dTable.Columns.Add("Test2");
dTable.Columns.Add("Test3");
DataRow ttt = dTable.NewRow();
ttt["Test1"] = "a";
ttt["Test2"] = "b";
ttt["Test3"] = "c";
dTable.Rows.Add(ttt);
var testList = from dtable in dTable.AsEnumerable()
select new testClass
{
Test1 = Convert.ToString(dtable["Test1"]),
Test2 = Convert.ToString(dtable["Test2"]),
Test3 = Convert.ToString(dtable["Test3"])
};
Try above code with your varible
hope this help.