field in datasource not accessible through code

T

TomVervoort

Hi,

I've created an InfoPath 2007 browser compatible form in Visual Studio 2008.
This form is already in production for quite some time now, and we never had
any problems with it.

Because I was asked to add new functionality to this form, I fired up my VS
again and started modifying the form. I added an extra field in the
datasource (in an already existing repeating group) and was trying to access
this field in code. However, every time I tried to access this field, I got
an 'object not set to an instance of an object' exception. The field on the
form also didn't show it's default value.

I extracted the xsn file and checked all files (template.xml,
sampledata.xml, myschema.xsd...) and they all contained the field.

Because I thought I did something wrong, I got the latest version from
source control and started all over again... same result. Strange thing is
that I can add extra fields directly under the root node. Just not in any of
the already existing repeating groups.

Did any of you ever had the same issue (and found a solution for it) ? I
prefer not to start from scratch again, because it's a complex form with
quite some code behind.

Any help appreciated !


Regards,

Tom
 
T

TomVervoort

Sure...

I had a method in my code behind that cleared the form. This method was
called everytime before new data was loaded. In the ClearForm() method, I
did something like this:

MainDatasource.CreateNavigator().SelectSingleNode("my:Form/my:Group",
NamespaceManager).InnerXML = string.Empty;

After retreiving the data, I recreated all nodes filled with this data.
However, I forgot to create the node for the new field inside my:Group.
Therefore, I got an object reference not set to an instance of an object
exception.


Regards,

Tom


"Kalyan G Reddy MVP (GGK Tech)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top