I have the following code and when saving in my database I get the following error: "Object reference not established as an instance of an object"
Imports MySql.Data.MySqlClient
Public Class Ingresovehiculo
Dim conexion As MySqlConnection
Dim Comando As MySqlCommand
Private Sub BtnSalir_Click(sender As Object, e As EventArgs) Handles BtnSalir.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub Ingresovehiculo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
conexion.ConnectionString = "server=localhost; user=root; password=;database=almacenca;"
conexion.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Btnagregar_Click(sender As Object, e As EventArgs) Handles Btnagregar.Click
Try
Comando = New MySqlCommand("INSERT INTO ingresovehiculo(tipo, marca, modelo, descripcion)" &Chr(13) &
"VALUES(@tipo,@marca,@modelo,@descripcion)", conexion)
Comando.Parameters.AddWithValue("@tipo", ComboBox1.SelectedValue)
Comando.Parameters.AddWithValue("@marca", ComboBox2.SelectedValue)
Comando.Parameters.AddWithValue("@modelo", Txtmodelo.Text)
Comando.Parameters.AddWithValue("@descripcion", Txtdescripcion.Text)
Comando.ExecuteNonQuery()
MsgBox("DATOS GUARDADOS")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class