2

I have a DataTable that has these columns:

AlertEmail , ClosingDate , OpeningDate , LocationTitle , JobTitle

I want to Search this DataTable and find Records for each AlertEmail. I do this but MailInfo returned NULL.

DataTable dt = amail.GetAllJobAlertForSend();

var AllEmail = dt.AsEnumerable()
                 .Select(row => new {attribute1_name = row.Field<string>("AlertEmail") }).Distinct();

foreach (var mail in AllEmail)
{
    var MailInfo = from p in dt.AsEnumerable()
                   where p.Field<string>("AlertEmail").Trim() == mail.ToString()
                   select new
                   {
                       ClosingDate = p.Field<DateTime>("ClosingDate"),
                       OpeningDate = p.Field<DateTime>("OpeningDate"),
                       LocationTitle = p.Field<string>("LocationTitle"),
                       JobTitle = p.Field<string>("JobTitle")
                   };

    foreach (var info in MailInfo)
    {
        Response.Write(string.Format("{0}", info.ClosingDate));
    }
}

What was wrong in my code?

3
  • 3
    I think you need to use mail.attribute1_name instead of mail.ToString() Commented Apr 12, 2016 at 8:27
  • @Viru, Thank you so much. my problem was solved Commented Apr 12, 2016 at 8:46
  • Glad I could help :)...Posted it as answer Commented Apr 12, 2016 at 8:48

1 Answer 1

1

As mail is object of anonymous class...Accessing its property will solve your problem instead of ToString

 var MailInfo = from p in dt.AsEnumerable()
                   where p.Field<string>("AlertEmail").Trim() == mail.attribute1_name
                   select new
                   {
                       ClosingDate = p.Field<DateTime>("ClosingDate"),
                       OpeningDate = p.Field<DateTime>("OpeningDate"),
                       LocationTitle = p.Field<string>("LocationTitle"),
                       JobTitle = p.Field<string>("JobTitle")
                   };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.