从vb.net检查mysql中的特定行和列

qvsjd97n  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(370)
Using conn As New MySqlConnection("server=localhost;user=root;password=;database=dbrentalsystem")
        conn.Open()
        Dim commandReader As New MySqlCommand("select * from tbl_unit", conn)
        Dim reader As MySqlDataReader = commandReader.ExecuteReader
        While reader.Read
            If reader.IsDBNull(2) Then
                lblUnit1.Text = "Vacant"
            Else
                lblUnit1.Text = "Occupied"
            End If
        End While
        commandReader.Dispose()
        reader.Close()
        con.Close()
    End Using

这是我的代码,我只想检查第2列第3行是否有数据

fcg9iug3

fcg9iug31#

一种快速且有点脏的方法是在reader中添加count和count到3。。这不是任务的最佳解决方案,但它会起作用:)

Using conn As New MySqlConnection("server=localhost;user=root;password=;database=dbrentalsystem")
    conn.Open()
    Dim commandReader As New MySqlCommand("select * from tbl_unit", conn)
    Dim reader As MySqlDataReader = commandReader.ExecuteReader
    Dim i as integer = 1
    While reader.Read
        if i = 3 then
           If reader.IsDBNull(2) Then
               lblUnit1.Text = "Vacant"
           Else
               lblUnit1.Text = "Occupied"
           End If
        end if
    i += 1
    End While
    commandReader.Dispose()
    reader.Close()
    con.Close()
End Using

相关问题