Hi, I'm evaluation Aspose.Words and trying to make a mailmerge. All things are going fine until know. I want to insert in a document a generated field and store this in the SQL server. Therefore i need the key of the record which is "current" in the merge. Of course the key must be available in the dataset.
Until now i have the following code:-
Private Sub HandleMergeHtml(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeFieldEventArgs)
....
' working code
...
Else
If e.DocumentFieldName = "Client_emailbevestigingscode" Then
' generate the value for Client_emailbevestigingscode giving ABC
' get from the current datatable from the current row which now is in the merging proces the value of field XYZ
builder.MoveToMergeField(e.DocumentFieldName)
builder.Write(ABC)
DoSQLUpdate(XYZ,ABC)
Dim CurrentIndex As Integer = e.RecordIndex() ???
Dim CurrentTable As String = e.TableName ????
End If
End If
The question is how to obtain the value of field XYZ. Do you have a code sample for me?
BTW: i filled the feeding table with the following code:
Dim ClientsSelected As DataTable = ExecuteDataTable(ReportsSQL)
'Once we have a document, we can save it to a file, stream or send to the client browser.
'We just send the documentto the browser here in the format selected by the user.
Document.MailMerge.Execute(ClientsSelected)
Document.Save("Aspose.Words.Demos.doc", SaveFormat.FormatDocument, SaveType.OpenInBrowser, Me.Page.Response)
Me.Page.Response.End()
' vervolgens moet de gebruiker worden "geprompt" om het resultaatbestand
' te accepteren.
End If
End Sub
Protected Function ExecuteDataTable(ByVal commandText As String) As DataTable
'I use "try" instead of "using" because my converter to VB code does not support "using".
Dim connStr As String = "Provider=SQLOLEDB.1;Password=fhrv84;" & _
"Persist Security Info=True;User ID=SA;" & _
"Initial Catalog=ApotheekOnline;" & _
"Data Source=LAB-2\LABWILLEM;Connect Timeout=15"
Dim conn As OleDbConnection = Nothing
Try
conn = New OleDbConnection(connStr)
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(commandText,conn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim table As DataTable = New DataTable
da.Fill(table)
Return table
Finally
If Not conn Is Nothing Then
conn.Close()
End If
End Try
End Function
Many thanks, Aat Jan