0
Answer

Word mail merge using datatable

Anthony Clarke

Anthony Clarke

13y
9.9k
1

Hi,
Im new to using word with C# and was wondering whether you could help me.
I need to make a mail merge from a datatable....e.g.
Datatable is source from an SQL server e.g. Name, Address, PostCode.
And here is my code for word so far. How do i go about inserting and printing everything - well say i have 5 records..
Thanks for your time
namespace
ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
dynamic wordApp = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
dynamic document = wordApp.Documents.Add();
document.Activate();
document.Content.InsertAfter(
"Type what i want");

wordApp.Visible =
true;