Click here to Skip to main content
14,661,076 members
Rate this:
Please Sign up or sign in to vote.
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
lw@zi 10-Aug-11 2:41am
   
You find a lot of sample code for that. Try Google.

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
vivek_cool 10-Aug-11 2:49am
   
sry friend this link not helping me
Rate this:
Please Sign up or sign in to vote.

Solution 3

This is exactly what you want :
Storing binary data in SQL Server using EF[^]
   
Comments
edjeit 25-Sep-13 10:29am
   
Why would this be downvoted?
Rate this:
Please Sign up or sign in to vote.

Solution 4

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);


}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100