Hi there,
I have been trying solve my error at this codes, it takes me too long.
Code:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim comm As String
Dim myconnstring As String
Dim UserID As Integer
Dim myReader As MySqlDataReader
Dim pword As String = PasswordTextBox.Text
myconnstring = "datasource=localhost;username=****;password=********;database=newscoring;"
conn = New MySqlConnection(myconnstring)
comm = "SELECT a.`uname`, a.`pword` FROM admin a where `pword` = " + pword
Try
conn.Open()
Try
myCommand.Connection = conn
myCommand = New MySqlCommand(comm)
UserID = myCommand.ExecuteScalar '**my program stops here.**
'Error:Connection must be valid and open.
myReader = myCommand.ExecuteReader
conn.Close()
While myReader.Read
TextBox1.Text = myReader.GetValue(myReader.GetOrdinal("pword"))
End While
If TextBox1.Text = PasswordTextBox.Text Then
Dim mainForm As New Form1
mainForm.UserID = UserID
mainForm.connectionString = myconnstring
mainForm.Show()
End If
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
conn.Dispose()
PasswordTextBox.Clear()
End Try
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
conn.Dispose()
PasswordTextBox.Clear()
PasswordTextBox.Focus()
End Try
End Sub
Error:
System.InvalidOperationException was unhandled
Message="Connection must be valid and open."
Source="MySql.Data"