12-18-2010, 12:53 PM
Well heres the code to read from a database :
Thats to open the connection. To check if a username exists, use this (for logging in)
Then to create a new account...
Hope this helps!
Code:
conn = New MySqlConnection
conn.ConnectionString = "server=SERVER.COM;Port=3306; user id=USERID; password=PASSWORD; database=DATABASE"
Try
conn.Open()
Dim sqlquery = "SELECT * From Users WHERE username='" & textbox1.text & "'"
Dim command As New MySqlCommand
Dim adapter As New MySqlDataAdapter
Dim data As MySqlDataReader
command.Connection = conn
command.CommandText = sqlquery
adapter.SelectCommand = command
data = command.ExecuteReader
Thats to open the connection. To check if a username exists, use this (for logging in)
Code:
If data.HasRows = 0 Then
MsgBox("Error! - Wrong User ID or Password", MsgBoxStyle.Critical, "Error!")
conn.Close()
Else
data.Close()
conn.Close()
command.Connection = conn
command.CommandText = "SELECT * From Users WHERE username='" & login_username.Text & "'AND PASSWORD='" & login_password.Text & "';"
conn.Open()
data = command.ExecuteReader
Then to create a new account...
Code:
sqlquery = "INSERT INTO Users (Username, Password) VALUES('" & txtbox_username.Text & "','" & txtbox_password.Text & "' )"
command.Connection = conn
command.CommandText = sqlquery
registerfinal.SelectCommand = command
data = command.ExecuteReader
MsgBox("Account has been created! - Please try logging in with these credentials to test the account!", MsgBoxStyle.Information, "Account Created!")
Hope this helps!