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]
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
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