Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 5th, 2009, 04:39 AM
Registered User
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Store the images to database directly

We often need to save and access images during our development. And most people do in the following way: save the image in the disk and then save image name in the database. Yet, sometimes we could also try to directly save the image in the database. Here I’d like to share how to store the images into sqlserver in winform with the help of Daolite as well as how to access them from sqlserver and display in picturebox. The whole process is very simple. Take Northwind as an example:
Firstly have a look at the Categories Table structure of Northwind Database.
[CategoryID] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [nvarchar](15) NOT NULL,
[Description] [ntext] NULL,
[Picture] [image]NULL,
We can see the data type of Picture field is image where we will save the image.
Simply use the following codes:
private void button2_Click(object sender, EventArgs e)

//declare data access objects
CategoriesAccess CateAcc = new CategoriesAccess();
Categories cate = new Categories();

//set value to newly added caregory
cate.CategoryName = "a new category";
cate.Description = "hello world";

// set value to Picture field
cate.Picture = CateAcc.UIDataConverter.ReadFile(@"F:\myproject\im ages\iphone-logo.jpg");

//insert newly added category into database
bool result=CateAcc.Insert(cate);

if (result)
//Completed. Images would be display in pictureBox.
this.pictureBox1.Image = CateAcc.UIDataConverter.ConvertToImage(cate.Pictur e);


Last edited by alenwu; January 5th, 2009 at 04:42 AM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
Store and Retrieve Images in SQL Database derekl ASP.NET 1.0 and 1.1 Professional 4 December 19th, 2007 03:16 AM
how to store images cancertropica SQL Server 2000 2 November 30th, 2007 03:18 PM
How can we store Images anujrathi SQL Server 2000 2 June 22nd, 2006 02:27 PM
Result Pagination not directly from database Wayang_Mbeling PHP How-To 2 June 9th, 2004 01:35 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.