//select all the names from database and loop through each row
for (int rowno = 0; rowno < oDataset.Tables[0].Rows.Count; rowno++)
{
//Incase there are more than one merge field
foreach (Word.Field myField in wordDoc.Fields)
{
//select merge field
myField.Select();
//Replace the selected merge field with the data
wordApp.Selection.TypeText(oDataset.Tables[0].Rows[rowno]["Name"]); }
wordDoc.SaveAs(ref oDataset.Tables[0].Rows[rowno]["Name"].doc,.............);
}
To Save the newly populated word document
- Then Save the new word document with the help of wordDoc.SaveAs() method. Here the SaveAs() method takes the destination file name along with some additional set of parameter.
Step 6: Quit the word application
- Then quit the word application with the help of wordApp.Application.Quit() method. This method also take some additional set of parameter.