แต่พออัพลงhost มันขึ่นเออเร่อว่า unable to connect to any of the specified mysql hosts อะคับแก้ยังไง
Code
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=.....; user id=......; password=......; database=......;"
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
mydata = command.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("Invalid user")
Else
MsgBox("Welcome user")
End If
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=.....; user id=......; password=......; database=......;"
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
mydata = command.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("Invalid user")
Else
MsgBox("Welcome user")
End If
End Sub
End Class