Solved

store image and retrieval from sql database

Posted on 2011-02-18
6
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 

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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

622 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