2013-04-18 68 views
0

我正在使用MS Access作爲數據庫的信息表格。通過VB查詢失敗(信息通道和訪問)

在窗體上,我想檢查電子郵件重複項,我試圖通過從下面的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) 

回答

0

試試這個:

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

或本:

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

+0

的第二行代碼的工作。但是,還有一個錯誤。將在晚上檢查它,並找回給你們!非常感謝!! – user2204330

+0

一切都超級好! ... 謝謝!! – user2204330