Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:06:20+00:00 2026-06-01T09:06:20+00:00

I have entered an image in sql server database successfully. Now i want to

  • 0

I have entered an image in sql server database successfully. Now i want to retrieve this image from database and show it in an Image control. I don’t want to put any ListBoxes on the page. I wrote in ASP dot Net..

Dim MS As MemoryStream
Dim IMG As System.Drawing.Image
Dim FS As FileStream
Dim FI As FileInfo
Dim IMGSTRM As Stream
Dim IMGBYTS As Byte()
Dim ImgData() As Byte

    CMD1 = New SqlCommand("select * from IMG where userid=0", CON1)
    If Not IsNothing(RDR1) Then RDR1.Close()
    RDR1 = CMD1.ExecuteReader()
    If RDR1.Read Then
        IMGBYTS = RDR1!img
        MS = New MemoryStream(IMGBYTS, False)
        IMG = Image.FromStream(MS)
        PIC1.ImageUrl = IMG
    End If

The problem is in the bold 2 lines above End If

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:06:22+00:00Added an answer on June 1, 2026 at 9:06 am

    if you are using the desktop application this is the solution

    Private Sub SqlBlob2File(ByVal DestFilePath As String)

        Dim PictureCol As Integer = 0 ' the column # of the BLOB field
        Dim cn As New SqlConnection("server=localhost;integrated security=yes;database=NorthWind")
        Dim cmd As New SqlCommand("SELECT Picture FROM Categories WHERE CategoryName='Test'", cn)
    
        cn.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        dr.Read()
        Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
        dr.GetBytes(PictureCol, 0, b, 0, b.Length)
        dr.Close()
    
        cn.Close()
    
        Dim ms As New System.IO.MemoryStream(b)
        Me.PictureBox1.Image = System.Drawing.Image.FromStream(ms)
    End Sub
    

    this is the link where you may want to look at : http://support.microsoft.com/kb/321900/en-us

    asp.net solution

    in case of web page or aspx page you can only show an image on a webpage from an Url, there is first should be a picture webpage as webform2 with only a picture box should have to be there. This page is the image for the webform1.

    In this way you can put as much pictures on a page as you want, depending of
    course that you make the same amount of pseudo pages (and don’t give them
    the same name).

    I hope it will be a nice pages.

    \\
    There has to be an imagebox, a button and a label on the webform1

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    Dim conn As New SqlConnection(connStr)
    Dim cmd As New SqlCommand("SELECT FileName, PictureID FROM Picture", conn)
    da = New SqlDataAdapter(cmd)
    cbd = New SqlCommandBuilder(da)
    dsPictures = New DataSet
    da.Fill(dsPictures)
    Me.Image1.Visible = False
    ListBox1.AutoPostBack = True
    Try
    ListBox1.DataSource = dsPictures.Tables(0)
    ListBox1.DataTextField = "FileName"
    ListBox1.DataValueField = "PictureID"
    ListBox1.DataBind()
    Catch sqlExc As SqlException
    Me.Label1.Text = "Database Error" 'sqlExc.ToString
    Catch exc As Exception
    Me.Label1.Text = "Datbase Connection Failed!"
    End Try
    conn.Close()
    End If
    End Sub
    
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    Session.Item("img") = ListBox1.SelectedItem.Value
    Image1.Visible = True
    Image1.ImageUrl = "http://localhost/testSQLPlaatjesWeb/WebForm2.aspx"
    End Sub
    

    ///
    \\

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim conn As New SqlConnection(connStr)
    Dim sqlstr As String = String.Format("SELECT Picture FROM Picture WHERE
    (PictureID = {0})", CInt(Session.Item("img")))
    Dim cmd As New SqlCommand(sqlstr, conn)
    conn.Open()
    Dim rdr As SqlDataReader = cmd.ExecuteReader()
    rdr.Read()
    Response.BinaryWrite(CType(rdr.Item("Picture"), Byte()))
    rdr.Close()
    conn.Close()
    End Sub
    

    ///

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text-area where text and an image url is entered. Text is
I have created a user from openfire admin page. I have entered the username,
I need all records which have year entered from search criteria. for ex: String
I have an input of type text , from which I have already entered
Let's say I have a user that entered 12 links into the database but
I have that contains some text entered dynamically by the user from a web
I have used the following code before uploading an image into mysql database Before
From the image below. It can be seen that I have three table User,
I have an image pattern which I want to display in a UIImageView. The
I have information entered into a text box on an ASP.net 3.5 page. when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.