Hello
This is a TUT for forum admins out there (mainly) but can be used for others.
This connects to a remote database. I've modified a default code that many other users have used. I made it faster in the process of logging in.
First download this:
MySQL :: Download Connector/Net
Second import MySQL.Data from .NET Reference
Third, type in at the top of your code "Imports MySQL.Data.mysqlclient"
At the top of your form, dim a new MySQL Connector or:
Next on your form Startup or Load Declarations code, type in this:
Code:
conn = New MySqlConnection()
conn.ConnectionString = "server=SERVER URL or IP; user id=DATABASE USER; password=DB PASS; database=DATABASE NAME"
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error attempting to connect to server. The Mark M Server may be down.")
Me.Close()
End Try
Modify to your info
Next make two textboxes and 1 button (2 if you want one for exit)
Make the button say "LOGIN" and password textbox properties:
Double click the OK or LOGIN button and type this code (modify to your needs)
Code:
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM TABLE_HERE WHERE USERNAME_FIELD_HERE='" + TextBox1.Text + "' AND PASSWORD_FIELD_HERE'" + TextBox2.Text + "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'start query
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
'see if user exits.
If myData.HasRows = 0 Then
conn.Close()
conn.Open()
MsgBox("Wrong username or Password", MsgBoxStyle.Critical, "Error")
Else
Main.Show()
Me.Close()
End If
End If
Sorry ill modify it later(add explanation) i did this at 10 PM so i dont have much time
Thank me if this helped!
NOTE: YOU CAN TRY SSL IF YOUR WEBSITE SUPPORTS IT BUT I NEVER TRIED IT