title: Query through VB fails (Infopath and Access)
body: <p>I am working on an infopath form using MS Access as the database.</p>
  
  <p>On the form, I want to check emails for duplicates and I am trying to do this by running an SQL query from within the following VB code.</p>
  
  <pre><code>    Public Sub CTRL125_7_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
  
      Dim myAdoConnection As AdoQueryConnection = _
      DirectCast(Me.DataConnections("Mainconnection"), AdoQueryConnection)
  
  
      Dim mynav As XPathNavigator = _
      CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Candidate_Tracking_Database/@Email", NamespaceManager)
  
      Dim email As String
  
      email = mynav.InnerXml
  
      myAdoConnection.Command = _
      "select [Email] from [Candidate_Tracking_Database] where [Email] =" + email
  
      myAdoConnection.Execute()
      End Sub
  </code></pre>
  
  <p>I want to continue this with an If, then, else statement to prompt if the duplicate is found. However, I get the following error when I try to execute the code:</p>
  
  <pre><code>System.Net.WebException was unhandled by user code
  Message="The query method on the Document object failed.
  Operation aborted"
  </code></pre>
  
  <p><strong>What am I doing wrong?</strong> Thanks in anticipation of an answer.</p>
  
  <p><strong>Notes:</strong> </p>
  
  <p>I have Adapted the code from - 
      <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.adoqueryconnection.command.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-1" rel="nofollow">http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.adoqueryconnection.command.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-1</a></p>
  
  <p>Elements in the Code are: </p>
  
  <pre><code>Mainconnection = connection name
  "/dfs:myFields/dfs:dataFields/d:Candidate_Tracking_Database/@Email" = Xpath of the input text box
  [Email] = Field name in the [Candidate_Tracking_Database] table
  </code></pre>
  
  <p>Complete Error is: </p>
  
  <pre><code>System.Net.WebException was unhandled by user code
  Message="The query method on the Document object failed.
  Operation aborted
  "
  Source="Microsoft.Office.InfoPath.Client.Internal.Host"
  StackTrace:
     at      Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(OMCall d)
     at Microsoft.Office.InfoPath.Internal.AdoQueryConnectionHost.Execute()
     at Candidate_Registration.FormCode.CTRL125_7_Clicked(Object sender, ClickedEventArgs e) in C:\Infopath\InfoPath Projects\Candidate Registration\FormCode.vb:line 300
     at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
     at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
  </code></pre>