如果Else在Visual Basic中

时间:2014-01-06 20:18:42

标签: vb.net if-statement

我试着写一些有两种可能性的东西。如果数据库中的条目存在,则显示一个消息框,否则显示另一个消息框。

这是我到目前为止所拥有的

 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

对此进行编码的好方法是什么?我把它的大部分填写完毕 感谢

1 个答案:

答案 0 :(得分: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