2014-01-06 92 views
-1

我試着寫一些東西,有兩種可能性。如果數據庫中的條目存在,則顯示一個消息框,否則顯示另一個消息框。如果否則在Visual Basic

這裏是我迄今爲止

Dim dc = New DataTestDataContext 

Try 

     dc.SearchDealers(txtDealerName.Text, cmbDealerState.Text) 

     If (txtDealerName.Text <> Or cmbDealerState.Text <>) Then 
      MessageBox.Show("This Dealer Doesnt Exist", "Search Dealer", _ 
         MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) 
     Else 
      MessageBox.Show("Yes this dealer exists", "Search Dealer", _ 
         MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) 

     End If 

    Catch ex As Exception 

    End Try 

什麼是編寫一個很好的辦法嗎?我有大部分填寫 感謝

+3

什麼問題呢? –

+0

什麼是DataTestDataContext? – NoChance

+2

這個問題似乎是脫離主題,因爲它會適合更好的http://codereview.stackexchange.com/ –

回答

0

我計算出來以供將來參考,但是這是使用LINQ和沒有存儲的過程。

Dim dc As New DataTestDataContext() 

    Try 
     Dim q = _ 
      (From cvg In dc.GetTable(Of tblDealer)() _ 
      Where cvg.DealerName = txtDealName.Text And cvg.DealerState = cmbDealState.Text _ 
      Select cvg).SingleOrDefault() 

     If (q Is Nothing) Then 

      MessageBox.Show("No records exist for this Dealer") 
     Else 

      MessageBox.Show("Records exist, Edit and Click Update OR Click Delete Dealer to Remove") 
     End If 


    Catch ex As Exception 
     Throw ex 

    End Try