.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Showing image in picturebox from database

Posted By: Aamrapali Tamgadge     Posted Date: June 01, 2011    Points:5   Category :C#
hi can anyone solve my problm.
I have to show the image to the picturebox control from database where my image datatype is image. using where condition by id i have to show the image in picturebox in c sharp.net

Responses
Author: Sunil Yadav       [Moderator]   Accepted Answer   
Posted Date: June 02, 2011     Points: 40   
Author: Ravi Ranjan Kumar             
Posted Date: June 02, 2011     Points: 20   

Hi try another link to save and Get Image from Database using C#
http://www.codeproject.com/KB/cs/PictureBoxImage.aspx

Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com
Author: Gowthammanju             
Posted Date: June 02, 2011     Points: 20   

Perform the following steps:

create table as

CREATE TABLE [dbo].[Albums] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[desc] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Photos] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[desc] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[album_id] [int] NOT NULL ,
[photo] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


step2:crete The Stored Procedures as

CREATE PROC sp_GetPhotoAlbums AS
SELECT Albums.[id] AS AlbumID, Albums.[name] AS Album,
Albums.[desc] AS Album_Desc, Photos.[id] AS PhotoID,
Photos.[name] AS Photo, Photos.photo, Photos.[desc] AS Photo_Desc
FROM Albums INNER JOIN Photos ON Albums.[id] = Photos.album_id
ORDER BY Albums.[id]
GO

CREATE PROCEDURE sp_InsertPhoto
@name AS VARCHAR(50),
@image AS IMAGE,
@album AS INT
AS

INSERT INTO Photos ([name], photo, album_id)
VALUES (@name, @image, @album)

RETURN @@identity
GO

CREATE PROCEDURE sp_NewAlbum
@name AS VARCHAR(20)
AS

INSERT INTO Albums ([name])
VALUES (@name)

RETURN @@identity
GO


step3: download the attachment below


run and execute it


regards,
gowtham



Download Attachment

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Ravi Ranjan Kumar             
Posted Date: June 11, 2011     Points: 20   

Hey Try given code
on button Click Event

SqlCommand cmd = new SqlCommand("your Query using where Clause","Your Connection" );
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
byte[] imagedata = (byte[])dr[Index]; // Index must define like 0,1 as your column number
Image newImage;
//Read image data into a memory stream
using (MemoryStream ms = new MemoryStream(imagedata, 0, imagedata.Length))
{
ms.Write(imagedata, 0, imagedata.Length);

//Set image variable value using memory stream.
newImage = Image.FromStream(ms, true);
}
pictureBox1.Image = newImage;

}

Hey Don't forget to mention Using System.IO namespace to access it depended classes in code.


Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend