I'm trying to launch a command from this class:
Imports System.Data.OleDb
Imports System.IO
Public Class GestionSql
Private sReturn As String = ""
Private sConection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +Directory.GetCurrentDirectory() + "\TPV.mdb;"
Private oConection As OleDb Connection
Public oCommand As New OleDbCommand
Public Function Launch(ByVal value As String) As String
Try
oConection.Open()
oConection = New OleDbConnection(sConection)
oCommand.CommandText = Value
sReturn = oCommand.ExecuteNonQuery()
oConection.Close()
MessageBox.Show("La contraseña es: " + sReturn.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Return sReturn
End Function
End Class
In this class:
Public Class IDVendedor
Private GestionSql As New GestionSql
Private sCmd As String
Private sPass As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Montamos y lanzamos el comando
sCmd = "SELECT Password FROM Vendedores WHERE Id=" + id.Text
sPass = GestionSql.Launch(sCmd)
End Sub
End Class
I miss the error:
Reference to object not established as an instance of an object. It tells me that the error is in ExecuteNonQuery in the sCmd parameter.