query data source - InfoPath Dev
in

InfoPath Dev

query data source

Last post 05-05-2005 12:20 PM by Agni Jonnalagadda. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-02-2005 09:08 AM

    query data source

    I'm a bit confused. In the rules box of a conttrol, I see that I can query a data source. My confusion is I do I use the result? When you do a query is it possible to determine if it succeed or not?

    I'm using Infopath to maintain a simple database. When the key field is entered, I want to query and see if the key has been previously entered. If so, populate the form with values that can be edited. If not, skip the prepopulate. Have I missed something so very obvious?
  • 05-03-2005 05:40 AM In reply to

    Yes it is possible to check whether the query is successful or not, You need to check for the number of rows that the dataconnection XML has.
    For that you can use the "count()" method. For ex: It could be like this
    "count(xdXDocument:GetDOM("NameTable")/dfs:myFields/dfs:dataFields/d:Table)"

    Where "NameTable" is your secondary dataconnection name which points to your table.
    And you should specify a filter on the xpath to check for the row that you want to Insert.
    Now your total condition will be
    "count(xdXDocument:GetDOM("NameTable")/dfs:myFields/dfs:dataFields/d:TableName[@name = 'abcd']) > 0"

    If this condition is true then it means that there is a row in the table already, and if the condition return false then row is not there in the table.

    There is another way of doing this through the code,
    Write some code to change the Command that executes when you query a database

    ADOAdapterObject oNameTable = (ADOAdapterObject) thisXDocument.DataAdapters["NameTable"];
    oNameTable.Command = string.Format("Select * from tableName where name = '"+name+"'", sMemberId);
    oNameTable.Query();

    //After above code gets executed check how many rows are present in the data connection
    IXMLDomNodeList oNodeList = thisXDocument.GetDOM("NameTable").selectNodes("dfs:myFields/dfs:dataFields/d:TableName");
    Now if oNodeList.length is greater than "0" then the row is already present in the code.

    Hope this Helps!


    Agni
    InfoPathDev India
  • 05-05-2005 05:58 AM In reply to

    Thanks for the code sample this was helpful. I still don't understand the proper use of the "query data connection" action in a rule. While you can query a specific source, what is the output of the query? That is what is not clear to me.
  • 05-05-2005 12:20 PM In reply to

    "Query data source" queries not only Database dataconnections, but also Webservice connections. So people might want to query a datasource once an action is performed For ex: when a button is clicked they might want to query a dataconnection, which gets data into a dataconnection.

    In your case you wanted to query a database to check whether the name exists in the database. Similarly someone else might want to populate a dropdown list based on another field value. In this instance once they query the dataconnection the data will populated into a dropdownlist.

    Hopefully this could have answered your question.

    Agni
    InfoPathDev India
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.