Click here to Skip to main content
13,793,266 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have a program with search button, picture box, and textbox for file image path, i want to search invoice number and show the pictures and picture path in textbox but the code won't to process, can you help me with this codes??

What I have tried:

Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click
        command.Connection = con
        Try
            str = "Select * from datagambar Where NoFaktur = @nofaktur"
            command = New OleDbCommand(str, con)
            command.Parameters.Add("@nofaktur", OleDbType.VarChar).Value = nofaktur.Text
            command.ExecuteNonQuery()
            Call showimage1()
            command.Dispose()
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Sub showimage1()
        PictureBox1.Visible = True
        PictureBox1.Image = Image.FromFile("G:\Aplikasi\Photo\Faktur Invoice")
    End Sub
Posted 6-Sep-18 18:51pm
Updated 7-Sep-18 4:40am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.181207.3 | Last Updated 7 Sep 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100