I am creating a login form together with sql as may databse but when i run may program an error occur at "myData = myCommand.ExecuteReader()" stating that "Connection must be valid and open" what should i do on that to make it fix??
someone help me please
thanks in advance
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class Login
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim conn As MySqlConnection
conn = New MySqlConnection()
conn.ConnectionString = "server=112.200.62.203; user id =root; password=; database=sample"
Try
conn.Open()
Catch ex As Exception
MsgBox("Error")
End Try
Dim MyAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM tbllogin Where username='" & txtUsername.Text & "' and password='" & txtPassword.Text & "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
MyAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
If myData.HasRows = 0 Then
MsgBox("Invalid Login", MsgBoxStyle.Critical)
txtUsername.Clear()
txtPassword.Clear()
Else
MsgBox("Login Successful")
ProfileForm.Show()
Me.Hide()
End If
End Sub