Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySqlConnection As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = "server=localhost; user id=root; password=1234; database=1; Pooling=false"
Try
MySqlConnection.Open()
MessageBox.Show("Connection to Database has been opened.")
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT * FROM user WHERE username = '" & UsernameTextBox.Text & "' AND password = '" & PasswordTextBox.Text & "';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquary
myadapter.SelectCommand = command
Dim mydata As MySqlDataReader
If mydata.HasRows = 0 Then
MsgBox("ผิดพลาด", MsgBoxStyle.Exclamation)
Else
MsgBox("ถูกต้อง", MsgBoxStyle.Information)
Form2.Show()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySqlConnection As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = "server=localhost; user id=root; password=1234; database=1; Pooling=false"
MySqlConnection.Open()
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT * FROM user WHERE username = '" & UsernameTextBox.Text & "' AND password = '" & PasswordTextBox.Text & "';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquary
myadapter.SelectCommand = command
Dim mydata As MySqlDataReader
If mydata.HasRows = 0 Then
MsgBox("ผิดพลาด", MsgBoxStyle.Exclamation)
Else
MsgBox("ถูกต้อง", MsgBoxStyle.Information)
Form2.Show()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class