// Getting the DataTable
var trans = util.sql.sqlToTable("Select idPage,PageType,Front,Back From dbo.GetTransactionImageURLs_ForSplit(@transId)", new SqlParameter("@transId", idTransaction));
// Creating new List
List<string> ImgUrlList = new List<string>();
// Select desired columns from datatable using LINQ and save them into new object
// Way #1
var ImgUrl = trans.AsEnumerable().Select(
r=> new
{
FrontImg = "{ type: 'image', url: '" + r.Field<string>("Front") + "'}",
BackImg = "{ type: 'image', url: '" + r.Field<string>("Back") + "'}",
}).ToArray();
// Way #2
foreach(var img in trans.AsEnumerable())
{
if (img.Field<object>("Front") != DBNull.Value) ImgUrlList.Add("{ type: 'image', url: '" + img.Field<string>("Front") + "'}");
if (img.Field<object>("Back") != DBNull.Value) ImgUrlList.Add("{ type: 'image', url: '" + img.Field<string>("Back") + "'}");
}
// Pushing items from object to list
foreach (var i in ImgUrl)
{
ImgUrlList.Add(string.Join(",", i.FrontImg.ToString()));
ImgUrlList.Add(string.Join(",", i.BackImg.ToString()));
}
// Somwhere else in code when needed to be used as string
string str = string.Join(",", ImgUrlList.Cast<string>())