Hello all,
I am trying to make this login page for users, but when I go to login it gives me an Error or just does not work.

Here is what I am using.

Imports MySql.Data.MySqlClient
Public Class Form1
    Public conn As MySqlConnection
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text & TextBox2.Text = "" = True Then MsgBox("Incorrect Information, please try again!", MsgBoxStyle.Information, "Login Error")
        conn = New MySqlConnection("server=localhost; user id=example; password=example; database=example")
        Try
            conn.Open()
            Dim sqlquery As String = "SELECT * FROM logins WHERE username = '" & TextBox1.Text & "';"
            Dim data As MySqlDataReader
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            command.CommandText = sqlquery
            command.Connection = conn
            adapter.SelectCommand = command
            data = command.ExecuteReader
            While data.Read()
                If data.HasRows() = True Then
                    If data(2).ToString = TextBox2.Text Then
                        MsgBox("You have logged in " & TextBox1.Text, MsgBoxStyle.Information, "Logged in!")
                        Form3.Show()
                    Else
                        MsgBox("Incorrect information")
                    End If
                End If
            End While
        Catch ex As Exception
            MsgBox("Error!")
        End Try

    End Sub
End Class

If you see any errors could you please notify me? Thanks

Please post error message or stack trace here.

Have a look at line #5,

if TextBox1.Text.Length=0 and TextBox2.Text.Length=0 then
  ...
  ... 'stop the execution of this method
  Return 
 End If

And change sql statement,

Dim sqlquery As String = "SELECT * FROM `logins` WHERE `username` = '" & TextBox1.Text & "'"

Edited 5 Years Ago by __avd: n/a

Okay I fixed it, this was A database error, I had to change the order of the Rows.

This article has been dead for over six months. Start a new discussion instead.