Trouble with creating error messages when a query fails to return the data to the infopath form - InfoPath Dev
in

InfoPath Dev

Trouble with creating error messages when a query fails to return the data to the infopath form

Last post 02-25-2011 09:17 AM by g21cincy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-22-2011 06:09 AM

    Trouble with creating error messages when a query fails to return the data to the infopath form

     Hello all,

     

    I have designed forms in infopath that queries a sql table and based on the Id_number submitted , returns the details of the customer.

    The problem is in case an Id_number for which no data is present inthe sql table is submitted, the form jst gives error like "could not connect to the data source or the session time out". I would like to customize the error here , like giving out a dialog box saying "invalid Id_number".

     

    How do I do this?

     

    To query the table I have used a web service which submits Id_number to the table.

     

    Thanks..
  • 02-22-2011 07:36 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Trouble with creating error messages when a query fails to return the data to the infopath form

    I usually do this in the code behind the button. Here is the code I use. I hope this helps you out.

    Dim Nav As XPathNavigator = Me.CreateNavigator()

    Dim Query As AdoQueryConnection = Me.DataConnections("Data Source Qry")

    Query.Command = "SELECT Id_number FROM MedForms.dbo.tblTable WHERE Id_number = '" & GetValue("XPath", Nav) & "'"

    Query.Execute()

    Dim IDNumberNav As XPathNavigator = Me.DataSources("Data Source Qry").CreateNavigator()

    Dim IDNums As XPathNodeIterator = HospitalAcctNav.Select("/dfs:myFields/dfs:dataFields/d:tblTable", Me.NamespaceManager)

    If IDNums.Count = 0 Then

    Dim HospitalAcctInput As XPathNavigator = Me.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/q:tblTable/@ID_Number", Me.NamespaceManager)

    Me.Errors.Add(HospitalAcctInput, "Error", "Invalid ID Number")

    Else

    ' Run query using Data Source

    End If

    Return

    End If

  • 02-22-2011 09:13 PM In reply to

    Re: Trouble with creating error messages when a query fails to return the data to the infopath form

     Thanks a lot g21cincy...

    But u will be dismayed to know that I have absolutely no idea about coding using infopath..

    and so i don understand the code above ;-(

    Can u please be kind enuf to explain me the variables and keywords used in the code like , Dim (which seems to be a keyword), Me.CreateNavigator , MedForms.dbo.tblTable.. ???

     Thanks in advance

  • 02-25-2011 09:17 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Trouble with creating error messages when a query fails to return the data to the infopath form

    I hope this helps you out.

    Dim Nav As XPathNavigator = Me.CreateNavigator()

    ' Set the data connection for the query

    Dim Query As AdoQueryConnection = Me.DataConnections("Data Source Qry")

    ' This part is where the query is done to see if the Id_number exists

    Query.Command = "SELECT Id_number FROM MedForms.dbo.tblTable WHERE Id_number = '" & GetValue("XPath", Nav) & "'"

    Query.Execute()

    Dim IDNumberNav As XPathNavigator = Me.DataSources("Data Source Qry").CreateNavigator()

    Dim IDNums As XPathNodeIterator = HospitalAcctNav.Select("/dfs:myFields/dfs:dataFields/d:tblTable", Me.NamespaceManager)

    ' If there are no matches for the Id_number then an error is thrown which will have a red dotted line around the text box being queried and say "Invalid ID Number"

    If IDNums.Count = 0 Then

    Dim HospitalAcctInput As XPathNavigator = Me.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/q:tblTable/@ID_Number", Me.NamespaceManager)

    Me.Errors.Add(HospitalAcctInput, "Error", "Invalid ID Number")

    Else

    ' Run query using Data Source

    End If

    Return

    End If

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