Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all I have been trying to add some DB functionality to one of my apps and not having much luck. Please keep in mind not using Data set using Data reader.
I have tried many ways to get my data from db to windows form into the picture box. I want the image to be placed in picture box based on what item is chosen in combo box. I am also having issues with loading other values into text strings based on what item in the DB is selected in the Combo box; see code. The code has many attempts of image from SQLite db to picture box.

What I have tried:

VB
#Region "Data Test"
     Dim aidlink As String

    Const CONNECTION_STR As String = "Data Source=a2w;Version=3;"

    Private Sub ReadData()

        Dim objConn As SQLiteConnection
        Dim objCommand As SQLiteCommand
        Dim objReader As SQLiteDataReader

        Try

            objConn = New SQLiteConnection(CONNECTION_STR)
            objConn.Open()

            objCommand = objConn.CreateCommand()
            objCommand.CommandText = "SELECT [id],[aname] ,[fname] ,[slink] ,[aimg] From [apps] ORDER BY aname" ' "SELECT * FROM apps ORDER BY aname" 

            objReader = objCommand.ExecuteReader()

            ComboBox1.Items.Clear()
            While (objReader.Read())
                ComboBox1.Items.Add(objReader("aname"))

                Dim bytaimg(objReader.GetBytes(1, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte 'returns error "Specified cast is not valid"
                objReader.GetBytes(1, 0, bytaimg, 0, bytaimg.Length)
                Dim stmaimg As New MemoryStream(bytaimg)
                PictureBox1.Image = Image.FromStream(stmaimg)
                PictureBox2.Image = CType((objReader("aimg")), Image)




                Dim aid = ("steam://rungameid/" & (objReader("slink"))) ', String)
                aidlink = aid
                Dim tid = (objReader("slink"))

                Me.Text = CType(Application.ProductName & " " & "v" & Application.ProductVersion & " " & "App ID:" & " " & tid, String)

            End While

        Catch ex As Exception
            MessageBox.Show("An error has occurred: " & ex.Message)

        Finally

            If Not IsNothing(objConn) Then
                objConn.Close()
            End If
        End Try
        objConn.Close()
    End Sub

#End Region
Posted
Updated 2-Aug-17 23:11pm
v2
Comments
Richard MacCutchan 3-Aug-17 4:36am    
Most of your code is commented out. Please post the actual code that does not work and add comments only at the place where the errors occur.
sixxkilur 3-Aug-17 5:07am    
Thank you for the quick response I have updated the post to be cleaner.

1 solution

 
Share this answer
 
Comments
sixxkilur 3-Aug-17 5:31am    
How would I implement that in my code?
Richard MacCutchan 3-Aug-17 5:33am    
Look at the documentation to see what each parameter is, and what value it needs, to create the byte array for the data you are extracting.
sixxkilur 3-Aug-17 5:47am    
I have not a clue; I am not great at understanding MS and Technet guides I have better luck understanding what I can dig up on forums. But for over a week I have not had any luck solving the issue I have. all I know is I want to load a Blob
or image that is located in the database and place it in picture boxes based on what item is selected in combo box. Looking at the all of it and focusing on Byte arrays I am still lost. <url>https://msdn.microsoft.com/en-us/library/system.byte(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 The last two examples I do not see how those would work in my code example.
Richard MacCutchan 3-Aug-17 7:08am    
Sorry, but it is not possible to teach you the basics of VB.NET in QA. If you do not understand the difference between a Byte and a Byte[] then I suggest finding a good book or tutorial.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900