Can not pass Infopath field value as sql query

Hi,

I have a infopath form with text field.

I am doing the code for the form in vs

I am trying to pass one of the field value into a sql query in command text but while I am debugging it is giving the following error

Object reference not set to an instance of an object.

I chechekd the format that I wrote the string I think it is correct

it is as following

dim str as string = "select ExpenceAmount from Expenses where ExpenseID = " & ThisXDocument.DOM.selectstringNode("/my:mtFields/my:ExpenseID").text

cmd.commandtext = str

ExpenseID is the Field name

I am a begginer in infopath but I serached everything how to do and came until here but I was not able to debug what I did and was not able to work my code any help is really appreciated.

Thanks.

[847 byte] By [NelG1] at [2007-12-23]
# 1

Hi,

Can you check if the expression

ThisXDocument.DOM.selectstringNode("/my:mtFields/my:ExpenseID")

is returning a valid node. Looks like it may not be returning a valid node or the text on the node may be empty, causing the null reference.

HTH

MohitGupta-MSFT at 2007-8-31 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 2

Hey Thanks Mohit,

I figured it out . I am ooking for valus in an XML element where I have to look in for the attributes.

Thanks fro your response.

NelG1 at 2007-8-31 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 3

Hey this is for those who are looking for an answer. When you are passing values from infopath the format may be as I wrote in my previous question but actually you need look into the xml that is where your value is it there directly in the element of in a field or in a attribute

So if yor are trying to get valus try to first get into an xmlnode

i.e

dim xmlnode as IXMLDOMNode = thisDocument.DOM.SelectecSngleNode(":myfields/fields")

'''''when you are writing the singlenode stick your xml in notepad and see for the elements and the attributesin there to get the corret nalu out of a field rather than a null reference.

dim str as String = XMLNode.attributes.getNamedItem("FieldID").text

NelG1 at 2007-8-31 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...