Solved

store image and retrieval from sql database

Posted on 2011-02-18
6
442 Views
Last Modified: 2012-05-11
i am a newbie to visual basic .
by the code shown i can upload images to sql server.i tried many ways somehow i cant retrieve them and save them in a specific folder.
any help ?


table name :>  picture_pool

column name    data type
pic_id                 int
photo                 image
con.Open()

            Dim sql As String = "INSERT INTO picture_pool VALUES(@pic_id,@photo)"
            
            Dim cmd As New SqlCommand(sql, con)

            cmd.Parameters.AddWithValue("@pic_id", 1)

            Dim ms As New MemoryStream()

            '''''if i dont use msgbox the image does not appear ?? 
            MsgBox("File is Uploaded to server")

            PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)

            Dim data As Byte() = ms.GetBuffer()

            Dim p As New SqlParameter("@photo", SqlDbType.Image)

            p.Value = data

            cmd.Parameters.Add(p)

            Try
                cmd.ExecuteNonQuery()
            Catch ex As Exception
            End Try

            con.Close()

Open in new window

0
Comment
Question by:2dyazilim
6 Comments
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 100 total points
ID: 34924103
0
 
LVL 10

Assisted Solution

by:daryal
daryal earned 100 total points
ID: 34924118
Hello,
First of all, please consider if storing images in a sql server is a good decision. I do not know the project details, but generally it is wise to store images on the file system and store only the path or the name on the sql server.
check the links:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/52655606-6597-482b-81cd-9682115d1d7f
http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/5bbe8094-9936-4aca-bf6c-f7674b5eab2c
0
 
LVL 19

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 100 total points
ID: 34924119
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:2dyazilim
ID: 34924391
when i dont put the msgbox on the code above . it  doest not retrieve the image..  even if it is true. anysolution for that ?
0
 
LVL 7

Assisted Solution

by:EYoung
EYoung earned 100 total points
ID: 34927411
I store images in the file system and keep just the path in SQL.  That way the users can modify the images directly without the need of a program.  It works great.
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 100 total points
ID: 34932667
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question