Hi my code is as below:
List<COSIS_DAL.PaymentsHeader> pheadr = c.GetPaymentHeaderByPayDate(PayDate);
public List<PaymentsHeader> GetPaymentHeaderByPayDate(DateTime payDate)
{
CosisEntities db = new CosisEntities();
IQueryable<PaymentsHeader> query = (from p in db.PaymentsHeaders
where p.PaymentDate.Value.Day == payDate.Day
&& p.PaymentDate.Value.Month == payDate.Month
&& p.PaymentDate.Value.Year == payDate.Year
select p);
return query.ToList();
}
so I want to save the data from pheadr to a string like this:
string keyword = Convert.ToString(pheadr.Select(m => m.VoucherNumber));
but I am not getting the value inside the list. Instead of the value I am getting this:
System.Linq.Enumerable+WhereSelectListIterator`2[COSIS_DAL.PaymentsHeader,System.String]
Please help me on this. I am really in trouble for this. Thanks in advance.
The problem is that pheadr.Select(m => m.VoucherNumber) isn't a single value... It's a collection of values... You could try:
string keyword = string.Join(", ", pheadr.Select(m => Convert.ToString(m.VoucherNumber)));
if you really want multiple voucher numbers separated by a ,.
or you could put it in a separate collection:
List<string> vouchers = pheadr.Select(m => Convert.ToString(m.VoucherNumber)).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