Click here to Skip to main content
15,915,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi....
i stored image in sql 2008 database with data type image. Now i want to retrieve from Database..
How we can do this please hep me out!!!!!!!!
thanks.....
Posted
Comments
dan!sh 10-Aug-11 2:41am    
You find a lot of sample code for that. Try Google.

 
Share this answer
 
Comments
vivek_cool 10-Aug-11 2:49am    
sry friend this link not helping me
 
Share this answer
 
This is exactly what you want :
Storing binary data in SQL Server using EF[^]
 
Share this answer
 
Comments
edjeit 25-Sep-13 10:29am    
Why would this be downvoted?
Table for store image

CREATE TABLE [dbo].[atul](
[id] [int] IDENTITY(1,1) NOT NULL,
[img] [image] NULL,
CONSTRAINT [PK_atul] PRIMARY KEY CLUSTERED
(
[id] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO





Store procedure for retrieve image

create PROCEDURE [dbo].[ReadImage] @imgId int

AS
BEGIN

SET NOCOUNT ON;

SELECT img FROM atul
WHERE id=@imgId
END






code for display image which stored in sql-server through selected image-id

string i=txtimg.text;// image id
SqlCommand cmd = new SqlCommand("ReadImage", Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@imgId", SqlDbType.Int).Valu
Convert.ToInt32("i");
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > 0)
{

byte[] imageData = (byte[])dt.Rows[0]["img"];
Response.BinaryWrite(imageData);


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900