1

I'm struggling a little bit with this and can't seem to find an answer here. I am using the SautinSoft Document plug-in to create a mail merge in MS Word. The data source is my issue. My data in a DataTable, whereas the function they have coded to pass the data is in an anonymous array:

        var dataSource = new[] 
        { new { FirstName = "Hector", LastName = "Stupid", Age = "40" },  
          new { FirstName = "Penelope ", LastName = "Plank", Age = "25" }
        };

So, I need to iterate through my DataTable populating the fields into this format with their values.

Then, I execute the Mail Merge thus:

        dc.MailMerge.Execute(dataSource);

The question is how? Since the array is being statically populated. I've tried many solutions, passing either the DataTable, converting to a Dictionary, and .ToArray() over Ienumerable, but nothing seems to replicate this format.

Many thanks in advance.

2
  • Why is datasource.Select(row => new { FirstName = row.whatever, LastName = row.whateverelse, Age = row.whatever }).ToArray() not working for you? Commented Oct 4, 2018 at 18:43
  • Thank you, this is what I was looking for! Commented Oct 4, 2018 at 19:07

1 Answer 1

2

If I understand correctly you can try to use AsEnumerable method let DataTable to IEnumerable<Row> then use select fill data.

datasource
    .AsEnumerable()
    .Select(row => new {
        FirstName = row["FirstName"],
        LastName = row["LastName"],
        Age = row["Age"]
    }).ToArray()
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Works perfectly.
@DavyC No problem glad to help you can mark this answer if that help you :)

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.