SqlConnection myConn = new SqlConnection ("Data Source=W2K3-BASE;uid=test;pwd=test;Initial Catalog=northwind" );
// define the command query
string query = "Select description FROM Categories where categoryid = 1";
// initialize command object with the specified query and connection
SqlCommand myCommand = new SqlCommand ( query, myConn );
// open the data connection
myConn.Open ( );
// execute the command
string test = myCommand.ExecuteScalar().ToString();
// close the data connection
myConn.Close ( );
return test.ToString();
So do you need to insert into your template a single string value or data returned by a DataReader? In any case, using mail merge feature seems to be the best way of implementing your task. Basically, you must prepare your document by inserting there either separate merge fields or merge regions and pass your data source object to MailMerge.Execute or MailMerge.ExecuteWithRegions, respectively. Please refer to the Performing Mail Merge section of our Programmers Guide to know more.