我正在使用 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"
我究竟做错了什么?感谢期待答案。
笔记:
守则中的要素是:
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)