View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail merge from C# using DataSet as datasource


I need to be able to fill out these fields from a DataSet (DataTable
with n number of rows) using C#. All the guides I have been over all
use some form of SQL datasource.


That's because Word Mailmerge has no way to connect or bind to the data
stored in internal objects in your program. It can only connect to data
using a Word converter (internal/external), DDE, in the case of Access
databases and Excel workbooks, ODBC and OLEDB (and it can't yet use an
ADO.NET source, just in case you were wondering).

Prior to Word 2007, you really have two options:
a. turn your data source into something that Word can use, and use
MailMerge
b. don't use MailMerge - use C# to get the data from your DataSet and use
methods in the Word object to insert that data into your postcasrd document.
For example, you might be able to:
- use a { DOCVARIABLE } field instead of a { MERGEFIELD { field as a
"placeholder" for each item you want to insert
- in C#, for each 3 rows in your DataSet,
- copy the data in the DataSet into the relvant Word document
variables
- update the fields in the document
- print/output the document

There are other possibilities. A lot depends on whether you are trying to
create a completely automated process or whether you are trying to create
something where the users can edit the document and so on (in which case
things obviously get a lot more complicated).

In Word 2007 you have at least one other option, because you can bind things
called "content controls" to data stored in your docx. However, that's about
as much as I know about content controls - I suspect you would still have to
serialize your DataSet into XML at some point to make use of them, but I
really don't know yet.

Peter Jamieson

"Sparre" wrote in message
oups.com...
Hello

I'm pretty new to the whole mailmerge deal and the various guides to
mail merge haven't really helped me.

I need to print out a series of documents each containing 3 "post
cards", now I need to fill out the the names and adresses and other
various information for each card. I have a Word template containing
these 3 "cards" with a series of merge fields.

I need to be able to fill out these fields from a DataSet (DataTable
with n number of rows) using C#. All the guides I have been over all
use some form of SQL datasource.

How can I fill out eg. 13 of those "cards" using C# and a DataSet, and
is there special requirements to the type of mailmerge fields I use ?

Hope someone can help..... )

--
Sparre