Any fast way to convert a datatable to List<List<string>> ?
right now i am doing
for (int rowIndex = 1; rowIndex <= stats.EndRowIndex; rowIndex++)
{
List<string> lstOneRowElements = new List<string>();
for (int colIndex = 1; colIndex <= stats.EndColumnIndex; colIndex++)
{
lstOneRowElements.Add(excelDoc.GetCellValueAsString(rowIndex, colIndex).Trim());
}
lstAllData.Add(lstOneRowElements);
}
where
private List<List<string>> lstAllData { get; set; }
any better way to do it fast ?
If you have a DataTable (see comment Mithon) then you can try this
var q = from row in dt.AsEnumerable()
select row.ItemArray.Select(x => x.ToString()).ToList<string>();
var y = q.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With