Hello sir,
I want to convert a DataTable to IList in MVC using nHibernate
Convert DataTable To IList<T>
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 29, 2012, 10:42 PM EDT
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.