我正在尝试修复错误,但我仍然无法弄清楚这个错误的原因。如何解决这个问题?
保存按钮的vb代码
Private Sub Button1_SaveData_Click(sender As Object, e As EventArgs) Handles Button1_SaveData.Click
AddLeaseOfContract(TextBox10_Fla_MlaNo.Text)
End Sub
用于插入数据库的vb代码
Dim MysqlConn As MySqlConnection
Dim COMMAND As MySqlCommand
Private Sub AddLeaseOfContract(ByVal fla_mla_id As String)
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=;database=foreshore"
Dim Reader As MySqlDataReader
'For insert
'Try
MysqlConn.Open()
COMMAND.Connection = MysqlConn 'I got an error here
COMMAND.CommandText = "INSERT INTO foreshore.lease_of_contract(fla_mla_id) VALUES (@fla_mla_id)"
COMMAND.Prepare()
COMMAND.Parameters.AddWithValue("@fla_mla_id", fla_mla_id) 'insert id
COMMAND.ExecuteNonQuery()
Reader = COMMAND.ExecuteReader
'MessageBox.Show("Data Saved")
Console.Write("Data saved in AddLeaseOfContract function")
MysqlConn.Close()
'Catch ex As Exception
'MessageBox.Show(ex.ToString)
'Console.WriteLine(ex.ToString)
'Finally
MysqlConn.Dispose()
'End Try
End Sub