ExecuteNonQuery
is for executing commands like
INSERT
,
UPDATE
, or
DELETE
, which don't return any data.
To execute a
SELECT
query and read the results, use
the ExecuteReader
method[
^] instead.
Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click
Using command As New OleDbCommand("SELECT * FROM datagambar WHERE NoFaktur = @nofaktur", con)
command.Parameters.Add("@nofaktur", OleDbType.VarChar).Value = nofaktur.Text
Try
con.Open()
Using reader As OleDbDataReader = command.ExecuteReader()
If reader.Read() Then
Dim imagePath As String = reader.Field(Of String)("Your image path column name")
If String.IsNullOrEmpty(imagePath) Then
PictureBox1.Visible = False
Else
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(imagePath)
End If
... Load other columns into the UI here ...
Else
... No match: tell the user, and clear the UI here ...
End If
End Using
Catch ex As System.Data.Common.DbException
MsgBox(ex.Message)
Finally
con.Close()
End Try
End Using
End Sub