By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

Retrieving image from DB and to convert byte array value

P: 1
hi ,
i have problem with Retrieving image from DB
i have a table with image datatype
i store a file by using code as follows
--------------------------------------------------
string strType;
int intLength,intStatus;
Stream ipStream;
intLength = File1.PostedFile.ContentLength;
strType = File1.PostedFile.ContentType;
byte []imgContent = new byte[intLength];
ipStream = File1.PostedFile.InputStream;
intStatus = ipStream.Read(imgContent, 0, intLength);
SqlCommand cmd = new SqlCommand("sp_insert_image", connection);
cmd.Parameters.Add("@pname", SqlDbType.Image).Value = imgContent;
cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = strType;
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
cmd.ExecuteNonQuery()
----------------------------------
it inserted into db.

but ,

while reading from db,table value in dataset like as follows

SqlDataAdapter da = new SqlDataAdapter("select pname,type from img_tab ",con);
DataSet ds = new DataSet();
da.Fill(ds);

pname
---------
System.Byte[] ---------> it doesnt retrieve binary value.
--------------------------------

problem 2
---------------
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.ContentType = dr["type"].ToString();
Response.BinaryWrite(dr["pname"]); in this line error
}

Error 2 Argument '1': cannot convert from 'object' to 'byte[]' D:\velu\Image\readrealimage.aspx.cs 30 34 D:\velu\Image\

Error 1 The best overloaded method match for 'System.Web.HttpResponse.BinaryWrite(byte[])' has some invalid arguments D:\velu\Image\readrealimage.aspx.cs 30 13 D:\velu\Image\

so Help me to identify this
Mar 6 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.