Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

store image and retrieval from sql database

Posted on 2011-02-18
6
Medium Priority
?
453 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 400 total points
ID: 34924103
0
 
LVL 10

Assisted Solution

by:daryal
daryal earned 400 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 400 total points
ID: 34924119
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 400 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 400 total points
ID: 34932667
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

916 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