找回密码
 立即注册

QQ登录

只需一步,快速开始

ZenosZeng 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-4-23 08:57  /   查看:5202  /  回复:0
我们之前提供的邮件合并功能示例使用的是XML作为数据源,在实际项目中,将MS SQL Server作为数据源的情况更为常见。
不管使用什么样的数据源,其操作步骤都非常相似:我们需要循环所有的合并字段,并将这些字段与数据源中的特定列的数据进行合并。在该示例中,我们将使用DocumentServer命名空间中提供的适配器字段(MergeField类型),这些适配器字段可以用于创建/操纵特定的ApplicationField对象,而且不必手动修改ApplicationField.Parameters属性的值。
下面的代码演示了合并操作的处理过程:
  1. // loop through all fields to merge
  2.     // the text with the database content
  3.     foreach (TXTextControl.ApplicationField field in tx.ApplicationFields)
  4.     {
  5.         try
  6.         {
  7.             if (field.TypeName != "MERGEFIELD")
  8.                 return;

  9.             // create a new field adapter
  10.             TXTextControl.DocumentServer.Fields.MergeField mf =
  11.                 new TXTextControl.DocumentServer.Fields.MergeField(field);

  12.             if (this.customersDataSet.customers.Columns.Contains(mf.Name) == false)
  13.                 continue;

  14.             // merge the text
  15.             field.Text = this.customersDataSet.customers.Rows[dataGridView1.SelectedRows[0].Index][mf.Name].ToString();
  16.         }
  17.         catch (Exception exc)
  18.         {
  19.             MessageBox.Show(exc.Message);
  20.         }
  21.     }
复制代码
运行效果:

png

png


源码:MS SQLServer + VS2010 + TX17.0
tx_sql_db.zip (292.95 KB, 下载次数: 429)

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部