1

Alright, here's the deal. I am doing a data conversion where I'm taking data from two databases and putting it into another. I'm adding a list of contacts, and then I'm adding a list of communication records. In order to simplify the process, I made a small array of all of the communication records with the household address of the contacts. Now I'm trying to use a lambda expression to sort out email addresses from the array, but I'm having a problem. The code so far is as follows:

            DataRow[] Comms = dtComms.Select("household_id = " + previousID);

            if (Comms.Where(x => x.Field<string>("communication_type") == "Home Phone").Count() > 0)
            {
                string HomePhone = rNDigits.Replace(Comms[0].Field<string>("communication_value").ToString().Trim(), "");
                if (HomePhone.Length > 6)
                    oAddress._Phone = HomePhone;
            }
            if (Comms.Where(x => x.Field<string>("communication_type") == "Email").Count() > 0)
            {
                string FamilyEmail = rNDigits.Replace(Comms[0].Field<string>("communication_value").ToString().Trim(), "");
                if (FamilyEmail.Contains('@') && FamilyEmail.Contains('.'))
                    oAddress._FamilyEmail = FamilyEmail;
            }

The problem is that obviously, this always will return the first value in the array, which might not always be the one that I want. How can I change the code so that it selects only the value from the array that matches the entry containing the email? Or, is there a better way to search through values in an array?

ijb109
  • 942
  • 1
  • 19
  • 30

1 Answers1

2

I suggesting to use a simple for or foreach loop in this case, LINQ can't modify data only select it.

MichaelT
  • 7,574
  • 8
  • 34
  • 47