Solved

store image and retrieval from sql database

Posted on 2011-02-18
6
441 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

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