【问题标题】:Query through VB fails (Infopath and Access)通过 VB 查询失败(Infopath 和 Access)
【发布时间】:2013-04-12 03:37:11
【问题描述】:

我正在使用 MS Access 作为数据库处理信息路径表单。

在表单上,​​我想检查电子邮件是否有重复,我试图通过在以下 VB 代码中运行 SQL 查询来做到这一点。

    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

我想用一个 If,then,else 语句继续此操作,以提示是否找到重复项。但是,当我尝试执行代码时出现以下错误:

System.Net.WebException was unhandled by user code
Message="The query method on the Document object failed.
Operation aborted"

我做错了什么?期待答案。

注意事项:

我已从 - http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.adoqueryconnection.command.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

代码中的元素是:

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

完全错误是:

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)

【问题讨论】:

    标签: sql vb.net vba infopath2010 infopath-2007


    【解决方案1】:

    试试这个:

    myAdoConnection.Command = _ "select [Email] from [Candidate_Tracking_Database] where [Email] =" & email

    或者这个:

    myAdoConnection.Command = _ "select [Email] from [Candidate_Tracking_Database] where [Email] ='" & email & "'"

    【讨论】:

    • 第二行代码有效。但是,还有另一个错误。晚上会检查并回复你们!!非常感谢!!
    • 一切都超级好!! ...谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    相关资源
    最近更新 更多