Sql data in the template

Hi,

I have an c# aspx page where I want to render a ms word document with data out of a database, I use the following statement to get the data (example)

public SqlDataReader Testing()
{
    strConn = "Data Source=W2K3-BASE;uid=test;pwd=test;Initial Catalog=northwind";
    mycn = new SqlConnection(strConn);
    SqlCommand myda = new SqlCommand("Select description FROM Categories where categoryid = 1 ", mycn);
    myda.CommandType = CommandType.Text;
    mycn.Open();
    SqlDataReader ddsqlReader = myda.ExecuteReader(CommandBehavior.CloseConnection);
    return ddsqlReader;
}

How can I write the value I have selected in the testing method into a mergefield in the ms word document?

thanks in advance

this is the solution:

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();

Hi,

Thank you for considering Aspose.

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.