none
retrieving images sql database RRS feed

  • Question

  • I have a hosted database sql server 2014

    conect vb.net project


    It has only 3 rows and each row has a cell of images .

    cell image number 2


    I want to
    retrievethe three row in database images to a program with three  PictureBox

    at the same time
    The current method was used to
    retrieve only one image
    What is the best way to
    retriev 3images from a database to 3 PictureBox

    code retrieveonly one image

     Try
                conns.Open()
                Using table As DataTable = New DataTable
                    Using command As SqlCommand = New SqlCommand("SELECT IMAGEA from IMAGE_TBA where id=" & textid.Text, conns)
                        Using adapter As SqlDataAdapter = New SqlDataAdapter(command)
                            adapter.Fill(table)
                        End Using
                    End Using
                    For Each row As DataRow In table.Rows
                        Dim lb() As Byte = row("IMAGEA")
                        Dim lstr As New System.IO.MemoryStream(lb)
                        PictureBox1.Image = Image.FromStream(lstr)
                        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                    Next
                End Using
                conns.Close()
            Catch ex As Exception
    
            End Try

    Saturday, July 7, 2018 5:20 PM

All replies

  • I have a hosted database sql server 2014
    It has only 3 rows and each row has a cell of images .

    cell image number 2


    I want to
    retrievethe three row in database images to a program with three  PictureBox

    at the same time
    The current method was used to
    retrieve only one image
    What is the best way to
    retriev 3images from a database to 3 PictureBox

    code retrieveonly one image

     Try
                conns.Open()
                Using table As DataTable = New DataTable
                    Using command As SqlCommand = New SqlCommand("SELECT IMAGEA from IMAGE_TBA where id=" & textid.Text, conns)
                        Using adapter As SqlDataAdapter = New SqlDataAdapter(command)
                            adapter.Fill(table)
                        End Using
                    End Using
                    For Each row As DataRow In table.Rows
                        Dim lb() As Byte = row("IMAGEA")
                        Dim lstr As New System.IO.MemoryStream(lb)
                        PictureBox1.Image = Image.FromStream(lstr)
                        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                    Next
                End Using
                conns.Close()
            Catch ex As Exception
    
            End Try


    Saturday, July 7, 2018 3:26 PM
  • I want to retrievethe three row in database images to a program with three  PictureBox

    at the same time
    The current method was used to
    retrieve only one image
    What is the best way to
    retriev 3images from a database to 3 PictureBox

     You would have to execute your logic 3 times to retrieve the 3 images. 

    Saturday, July 7, 2018 8:44 PM
  • The following is a working example that is hard coded to get three images. With a little work the WHERE IN could be done dynamically rather than hard coded.

    I used the following MSDN code sample as a reference (which has the data class GetImageForumQuestion was written from but in that case a stored procedure which I altered for your question)

    https://code.msdn.microsoft.com/INSERT-Image-into-SQL-29dfc8ee?redir=0

    Public Function GetImageForumQuestion() As List(Of Bitmap)
        Dim bmpList As New List(Of Bitmap)
        Dim dtResults As New DataTable
    
        Using cn As New SqlConnection With {.ConnectionString = ConnectionString}
            Using cmd As New SqlCommand With {.Connection = cn, .CommandText = "SELECT ImageData FROM ImageData WHERE ImageId IN (1,3,7) "}
                cn.Open()
                dtResults.Load(cmd.ExecuteReader)
                For i = 0 To dtResults.Rows.Count - 1
                    Dim ms As New MemoryStream(CType(dtResults.Rows(i)("ImageData"), Byte()))
                    bmpList.Add(CType(Image.FromStream(ms), Bitmap))
                    ms = Nothing
                Next
            End Using
        End Using
        Return bmpList
    End Function

    Call where ops is a instance of a class.

    Dim images = ops.GetImageForumQuestion()
    PictureBox1.Image = images(1)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, July 7, 2018 11:31 PM
    Moderator
  • Please refrain from double posting. In the other post I've supplied a viable solution, make sure to read through what I wrote and take it slow and this will work. Note all the code I've presented happens in a class called from a form.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, July 7, 2018 11:33 PM
    Moderator
  • All thanks and appreciation for help

    Another request for the same subject
    I want to put a
    ProgressBarshowing the  progress of the process


    Sunday, July 8, 2018 9:48 AM
  • In regards to progress, that does not make sense. When I run the code above it takes milliseconds. Have you tried my code? and if so how long does it take to run?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Proposed as answer by monemas Sunday, July 8, 2018 11:00 AM
    Sunday, July 8, 2018 9:53 AM
    Moderator
  • I tried the code and it works well


    But the database has large rows
    The more time the database takes, the more time it takes to connect to the server and synchronize the data

    Sunday, July 8, 2018 10:10 AM
  • I tried the code and it works well


    But the database has large rows
    The more time the database takes, the more time it takes to connect to the server and synchronize the data

    In regards to "has large" rows, why would that matter when you indicated you only want three rows, one image returned for each id using WHERE IN ?

    In regards to "the more time the database takes..." I truly don't understand what this means. Returning three images has nothing to do with "synchronize data".

    In regards to "I tried the code and it works well", that means your question has been answered as stated in the initial post. You should mark my reply as answered if this is a true statement. Anything other than that deserves a new question.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, July 8, 2018 10:38 AM
    Moderator
  • Please refrain from double posting. In the other post I've supplied a viable solution, make sure to read through what I wrote and take it slow and this will work. Note all the code I've presented happens in a class called from a form.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    @Karen, why didn't you merge these?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, July 8, 2018 12:28 PM
    Moderator

  • profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    @Karen, why didn't you merge these?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Should have but didn't, was multi-tasking at that time and I think I was thrown with the link presented indicating a duplicate post. 

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, July 8, 2018 1:16 PM
    Moderator