-1

Hello I wanna make if statement with multiple MySQLdatareader. I dont know it will work or not. Someone help me for fixing my code, please. This is my sample code.

  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

1 Answers1

0

I'd suggest the code below. I did not try it but this is the general idea.

    Sub Emailusernameexist()
        Dim sCommand As MySqlCommand = New MySqlCommand("SELECT Email, Username, Completename FROM account WHERE Email = '" & TextBox5.Text & "'" OR Username = '" & TextBox4.Text, conn)
        RD = sCommand.ExecuteReader

        Try
            If RD.HasRows Then
                While RD.Read
                    Dim email as String
                    Dim userName as String
                    Dim cname As String

                    email = RD.GetString("email")
                    userName = RD.GetString("userName")
                    cname = RD.GetString("Completename")

                    if (not IsNull(email)) Then 
                        MsgBox("Sorry, your email have been registered by " + cname + "? Please login !", vbInformation)
                    elseif (not IsNull(userName)) Then 
                        MsgBox("Maaf, username was owned by  " + cname + " !", vbInformation)
                    endif
                End While
        Catch ex As Exception
        End Try
        conn.close()
    End Sub
Jean-François
  • 374
  • 3
  • 8
  • Yeah... As I wrote, I did not test the code. I edited my previous answer. This should work now. – Jean-François May 11 '16 at 13:58
  • with isnull not work, sir. But work with IsDBNull but when I check for just username, the result is MsgBox("Sorry, your email have been registered by " + cname + "? Please login !", vbInformation) – Muhammad Herru Ristian May 12 '16 at 08:31