如何在vb.net中的数据库中找不到记录

时间:2015-03-05 04:00:12

标签: vb.net

如何确保在sql查询时找不到记录,使用哪里得不到结果。

如果找到记录,我会使用此来源并为显示记录工作,但我不知道如何使用"如果那么其他"改变"而#34;

Sub usercheck()
    'Prepare Connection and Query
    dbconn = New MySqlConnection("Server=localhost;Database=user_team;Uid=root;Pwd=")


    strQuery = "SELECT * " & _
               "FROM tb_team_user WHERE user_ip = '" & lip.Text & "'"

    SQLCmd = New MySqlCommand(strQuery, dbconn)

    'OPEN THE DB AND KICKOFF THE QUERY
    dbconn.Open()

    DR = SQLCmd.ExecuteReader

    While DR.Read
        tbteam.Text = DR.Item("user_team")
    End While

End Sub

1 个答案:

答案 0 :(得分:0)

在while循环之前,您可以添加if语句以查看是否返回了任何行:

If DR.HasRows Then
    ' There was at least 1 row returned
Else
    ' There were no rows returned
End If