Solved

store image and retrieval from sql database

Posted on 2011-02-18
6
439 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
Comment Utility
0
 
LVL 10

Assisted Solution

by:daryal
daryal earned 100 total points
Comment Utility
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 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 100 total points
Comment Utility
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:2dyazilim
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now