I am stumped with this problem, my database is local host and every other form I have no issues with but here, when I click the update button, I get this error which is very frustrating as I am very sure the SQL connection should be open! My code for the button is given.
Error: 'Invalid attempt to read when reader is closed'
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=alpine;database=database1"
Dim Reader As MySqlDataReader
Dim vals(2, 2) As Decimal
vals(0, 2) = Convert.ToDecimal(Cbudget.Text.ToString - OutBox.Text.ToString + InBox.Text.ToString)
vals(1, 0) = Convert.ToDecimal(Newfigbox.Text.ToString)
vals(2, 0) = Convert.ToDecimal(OutBox.Text.ToString - InBox.Text.ToString)
vals(1, 1) = Convert.ToDecimal(FigureBox.Text.ToString + Newfigbox.Text.ToString)
Try
MysqlConn.Open()
Dim Query As String
Query = "UPDATE accounts SET Current_Budget='" & vals(1, 0) & "';"
Command = New MySqlCommand(Query, MysqlConn)
Reader = Command.ExecuteReader
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
MysqlConn.Close()
End Try
Try
MysqlConn.Open()
Dim Query As String
Query = "UPDATE stocktable, clientdetails SET stocktable.Quantity='" & vals(1, 1) & "', clientdetails.Balance='" & vals(2, 0) & "' WHERE 'stocktable.Type_Of_Metal' ='" & ComboBox1.Text & "' AND 'clientdetails.Name' ='" & ClientBox.Text & "';"
Command = New MySqlCommand(Query, MysqlConn)
Reader = Command.ExecuteReader
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
MysqlConn.Close()
End Try
Cbudget.Text = Nothing
Try
MysqlConn.Open()
Dim Query As String
Query = "SELECT Current_Budget FROM accounts"
Command = New MySqlCommand(Query, MysqlConn)
Reader = Command.ExecuteReader
MysqlConn.Close()
While Reader.Read
vals(0, 1) = Reader.GetDecimal("Current_Budget")
Cbudget.Text = vals(0, 1)
End While
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
MysqlConn.Close()
End Try
End Sub'