Mail Merging Query and Null Values

Hi,
I am trying to merge a a value into a document when the value of a field but I am having problems hadelling a null value. My code is this:

Private Sub MailMerge_MergeField_ReplaceValue(ByVal sender As Object, ByVal e As MergeFieldEventArgs)
If e.FieldName.Equals("CSV_FOOT_ACADEMY") And e.FieldValue() Is System.DBNull.Value = True Then
Dim builder As New DocumentBuilder(e.Document)
'Move document builder cursor to mergefield 
builder.MoveToMergeField(e.FieldName)
'Insert some text 
builder.Write("Hello from MergeField null value!")
ElseIf e.FieldName.Equals("CSV_FOOT_ACADEMY") And e.FieldValue.Equals("LUTON") Then
Dim builder As New DocumentBuilder(e.Document)
'Move document builder cursor to mergefield 
builder.MoveToMergeField(e.FieldName)
'Insert some text 
builder.Write("Hello from MergeField event handler!")
End If

The error I am getting is:
System.NullReferenceException was unhandled by user code
Message=“Object reference not set to an instance of an object.”
Is there a way around this problem?
Thanks
Frank

Hi

Thanks for your inquiry. You can check whether the value is null. You can try using the following code:

If e.FieldValue Is Nothing Then
'do something
End If

Hope this helps.
Best regards.

Hi,
I thought I was checking for nulls using this line:

If e.FieldName.Equals("CSV_FOOT_ACADEMY") And e.FieldValue() Is System.DBNull.Value = True Then

This does not work
How do I check for nulls?
Thanks
Frank

Hi
Thanks for your inquiry. System.DBNull.Value is not null. Please try using the following code:

If (e.FieldName.Equals("CSV_FOOT_ACADEMY")) And (Not e.FieldValue Is System.DBNull.Value) And (Not e.FieldValue Is Nothing) Then
'do something
End If

Hope this helps.
Best regards.

Hi,
I am still having difficulty with this line;

ElseIf e.FieldName.Equals("Foot_Acad") And e.FieldValue.Equals("no") Then

it gets to this line then I get the error:
System.NullReferenceException was unhandled by user code
Message=“Object reference not set to an instance of an object.”
Source=“App_Web_fo5ojvag”
However, I have check the test dataset I am using and there is a value of no in it…
Any idea what I could be missing?
Thanks
Frank

Ok,
I have figured out where it is going wrong;
the e.FieldName is looking at a diffrent field.
Is there any way to change the filed it is looking at/
Thanks
Frank

Hi

Thanks for your inquiry. You can map between names of fields in your data source and names of mail merge fields in the document. Please see the following link for more information.
https://docs.aspose.com/words/net/advanced-mail-merge-features/
Hope this helps.
Best regards.

Hi,
This is useful.
But will that change the vaiuye of e.FieldName?
Thanks
Frank

Hi

Thanks for your inquiry. You can use e.FieldName to get field name in your data source and e.DocumentFieldName to get name of field in the document.
Hope this helps.
Best regards.