Hi,
i'm doing a registration form and i have problems checking if the username exists in the database.
Imports MySql.Data.MySqlClient
Public Class Admin_Reg
Dim server As String = "Server=localhost;Database=escola_musica;Uid=root;Pwd=;"
Dim con As New MySqlConnection
Private Sub Admin_Reg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = server
Try
If con.State = ConnectionState.Closed Then
con.Open()
Else
con.Close()
MsgBox("Ligação falhada!!")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub admin_reg(ByRef sqlstate As String)
Dim sql_ver As String = "SELECT username FROM admin WHERE username = '" & user_box.Text & "'"
Dim cmd As New MySqlCommand(sql_ver, con)
Dim dr As MySqlDataReader
With cmd
.CommandText = sqlstate
.CommandType = CommandType.Text
.Connection = con
.ExecuteNonQuery()
End With
cmd = New MySqlCommand(sql_ver, con)
dr = cmd.ExecuteReader
con.Close()
Dim rowCount As Integer
If rowCount <> 0 Then
MsgBox("Sorry, this user already exists!")
Else
MsgBox("This username is not taken!")
End If
If pass_box.Text <> cpass_box.Text Then
MsgBox("Passwords não correspondem.")
Else
MsgBox("Adicionado com sucesso!!")
con.Dispose()
End If
End Sub
Private Sub reg_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reg_button.Click
Dim sql As String = "INSERT INTO admin (username, pass) VALUES('" & user_box.Text & "', '" & pass_box.Text & "')"
admin_reg(sql)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Login.Show()
Me.Close()
End Sub
End Class
Can someone help me?
Thank you,
PF2G