infopath 2007 coding issue

J

JohnE

I have the following in which I am not finding a solution. The form is a
questionnaire that has options for the user to select per question. The user
may choose not to answer a question. If that is the case then there is a
null. I am using the following 3 lines (the IF is a one liner so no end if
needed) but I get the blue squiggly under the DBNull.Value in the IF
statement. I need another pair of eyes to look at this and see what I am
missing or doing wrong.

Dim xQ1 As XPathNavigator =
root.SelectSingleNode("/my:myFields/my:Questionnaire_Section/my:Q1",
NamespaceManager)
Dim iQ1 As Int32
If xQ1.Value = "" Then iQ1 = DBNull.Value Else iQ1 =
Convert.ToInt32(xQ1.Value)

Thanks in advance to anyone who responds.
.... John
 
J

JohnE

I forgot to mention the error I get is

Value of type 'System.DBNull' cannot be converted to 'Integer'.
 
B

Ben Walters

John,
I'm assuming the Q1 field has been set to the correct type in InfoPath e.g.
whole number not string
if that is the case try using simply null rather than dbnull.value.

Hope this helps

Cheers
Ben Walters
 
J

JohnE

Ben, thanks for the response. Tried the 'Null' but get the message

"null is not declared. Null constant is no longer supported; use
System.DbNull.Value instead"

The DbNull thing doesn't seem to work either, unless I'm missing something,
and chance are I am.

Any other thoughts? I'll give it a try. I have 46 questions to do this with.

.... John
 
J

JohnE

Ben, i used just DBNull and it seemed to work. The only problem now is if
the person leaves the question blank (doesn't select an option) it puts in a
zero in the database field for the unanswered question. Unfortunately, zero
(0), does mean something in the scoring. So if the person leaves a question
blank, 'null' should be in the table field.
.... john
 
B

Ben Walters

Hey John,
Where are the items for your drop down list being sourced from?
I'm thinking you should be able to set the Value for the blank selection to
equal -1 that way it's still an integer but not 0

Hope this helps

Cheers
Ben Walters
 

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