-1

你好我想用多个 MySQLdatareader 做 if 语句。我不知道它会工作与否。请有人帮我修复我的代码。这是我的示例代码。

  Sub Emailusernameexist()
Dim sCommand1 As MySqlCommand = New MySqlCommand("SELECT * FROM account WHERE Email = '" & TextBox5.Text & "'", conn)
Dim sCommand2 As MySqlCommand = New MySqlCommand("SELECT * FROM account WHERE Username = '" & TextBox4.Text & "'", conn)
RD1 = sCommand1.ExecuteReader
RD2 = sCommand2.ExecuteReader
Try
    If RD1.HasRows Then
        While RD1.Read
            Dim cname As String
            cname = RD1.GetString("Completename")
            MsgBox("Sorry, your email have been registered by " + cname + "? Please login !", vbInformation)
        End While
    ElseIf RD2.HasRows Then
        While RD2.Read
            Dim cname As String
            cname = RD2.GetString("Completename")
            MsgBox("Maaf, username was owned by  " + cname + " !", vbInformation)
        End While
    End If
Catch ex As Exception
End Try
conn.close()
End Sub
4

1 回答 1

0

我建议下面的代码。我没有尝试过,但这是一般的想法。

    子邮箱用户名exist()
        Dim sCommand As MySqlCommand = New MySqlCommand("SELECT Email, Username, Completename FROM account WHERE Email = '" & TextBox5.Text & "'" OR Username = '" & TextBox4.Text, conn)
        RD = sCommand.ExecuteReader

        尝试
            如果 RD.HasRows 那么
                虽然 RD.Read
                    将电子邮件变暗为字符串
                    将用户名暗淡为字符串
                    暗淡 cname 作为字符串

                    电子邮件 = RD.GetString("电子邮件")
                    用户名 = RD.GetString("用户名")
                    cname = RD.GetString("完整名称")

                    如果(不是 IsNull(电子邮件))那么
                        MsgBox("对不起,您的邮箱已经被" + cname + "注册了?请登录!", vbInformation)
                    elseif (not IsNull(userName)) 然后
                        MsgBox("Maaf, 用户名归 " + cname + " !", vbInformation)
                    万一
                结束时
        抓住前任作为例外
        结束尝试
        conn.close()
    结束子
于 2016-05-11T06:56:31.533 回答