Click here to Skip to main content
12,548,135 members (48,191 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked

store and retrieve image to/from sql server database

, 5 Aug 2007
Rate this:
Please Sign up or sign in to vote.
simple save and fetche image toand from database


hi.I have a database for save large image and binary data. we use a simple method for save and retrieve image from sqlserver database.


this article useful for every application programmer in related work.

we use this method in LG-iomind company

Using the code

At first we have two main storedprocedure for save and retrieve image

CREATE PROCEDURE sr_fetch_image(@ID int) AS
    SELECT    [Name], Exc, Image_Data
    FROM         [dbimage].[dbo].[tbl_Image]
    WHERE [ID]=@ID

CREATE PROCEDURE [sr_insert_Image]
     @Name     [nvarchar](50),
     @Exc     [nvarchar](50),
     @Image_Data     [image])

AS INSERT INTO [dbimage].[dbo].[tbl_Image] 

and some code in C# for save and fetching

// Save image in database
OpenFileDialog odlg = new OpenFileDialog();
Cursor.Current = Cursors.WaitCursor;
Image bmp=Bitmap.FromFile(odlg.FileName);
System.IO.MemoryStream ms=new System.IO.MemoryStream();
sr_fetch_imageTableAdapter.Insert("df", "rer", ms.GetBuffer());
Cursor.Current = Cursors.Default;
// fetch data from database
sr_fetch_imageTableAdapter.Fill(dSMoblie.sr_fetch_image, 3);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Write(dSMoblie.sr_fetch_image[0].Image_Data, 0, dSMoblie.sr_fetch_image[0].Image_Data.Length);
Image bmp = Bitmap.FromStream(ms);
pictureBox1.Image = bmp;

note that sr_fetch_imageTabelAdapter is my table adapter that have to stored procedure for save and fetching


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

jalal khodabandeh
Web Developer
Greece Greece
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralGood Example try it Pin
mayurmv5-Sep-08 17:24
membermayurmv5-Sep-08 17:24 
Questionhow to call sql server 2005 cursors in vc++ by using ADO Pin
ram on c#11-Nov-07 22:40
memberram on c#11-Nov-07 22:40 
GeneralQuestion Pin
thund3rstruck6-Aug-07 2:03
memberthund3rstruck6-Aug-07 2:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 6 Aug 2007
Article Copyright 2007 by jalal khodabandeh
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid