Getting the last row in a datatable

Hi,
Thank you for all the great support that I get through this forum.
I am producing a report that displays a summary of a data import. I have a single table that lists all the exceptions from the import and why the item was rejected.
I also have a summary at the top of the page that displays two items:
Total items processed - easy - just get a row count
Total item rejected - my problem
I have added two extra fields to my datatable which are the counters for these two items. I need to get the last row of the datatable will will have the total items rejected.
At the moment the merge field it taking the top / first record. Is there any way to force it to use the last record?
Joe

Hi

Thanks for your inquiry. It is not quite clear for me what you would like to do. Please attach your template here and provide me your code.

Best regards.

Hi,
Please see the atttached template.
I basically build a datatable that contains exceptions to the import file. The 4 pieces of data are as follows:
MemberNumber - the number of the rejected entry
ErrorMessage - the reason for rejection
TotalRecords - a static entry that is written with each extra row. Contains the total number of records to import
ImportedRecords - a running total of imported records. Therefore the last row of the table will contain the total records imported successfully. This is what I want to populate the document with. At the moment, it is displaying data from the first row.
I hope this is clearer
Joe

Hi
Thanks for your explanation. As I understood you have the following datatable:

MemberNumber ErrorMessage TotalRecords ImportedRecords
1 Some error1 1 1
2 Some error2 2 2
3 Some error3 3 3

And you would like to get the following result:
Number of records in import file: 3
Number of records imported: 3
Exceptions:

Member Number Error Message
1 Some error1
2 Some error2
3 Some error3

So I think that you can try using the following code to achieve this.

// Open template
Document doc = new Document(@"477_110694_joedigiulio\in.doc");
// Execute mail merge
doc.MailMerge.ExecuteWithRegions(MyTable);
doc.MailMerge.Execute(MyTable.Rows[MyTable.Rows.Count - 1]);
// Save document
doc.Save("out.doc");

Also see attached document.
Best regards.

Hello Alexey,
Thank you for the code provided.
It works exacly as I wanted it to!
Kind regards,
Joe