Click here to Skip to main content
15,031,962 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Dear Sir,

Now i am doing one web application(Asp.net/c#).In this project i want to upload images to mysql and also i have to show images in gridview.Here i am taking images by using fileupload control.In database i have set one field as longblob and also i can upload images to mysql.In database size is showing.But i can not retrieve images to gridview.I can not see anything in gridview.This is uploading code
int imageFileSize = FileUpload1.PostedFile.ContentLength;
       
BinaryReader imageFileBinaryReader = new BinaryReader(FileUpload1.FileContent);
byte[] imageFileBinaryBuffer = imageFileBinaryReader.ReadBytes(imageFileSize);
MySqlParameter imageFileBinaryParam = new MySqlParameter("@Log", MySqlDbType.VarBinary, imageFileSize);
imageFileBinaryParam.Value = imageFileBinaryBuffer;
cmdsave.Parameters.Add(imageFileBinaryParam);
cmdsave.executenonquery();

This is the retrieving code in handler class
 HttpRequest imageRequest = context.Request;
 HttpResponse imageResponse = context.Response;


MySqlDataReader imageFromDbReader = imageFromDbCmd.ExecuteReader(CommandBehavior.SingleRow);
            if (imageFromDbReader.HasRows)
            {
                imageFromDbReader.Read();
                 string imageFileMIMEType = imageFromDbReader["ImageFileMIMEType"].ToString();
                  string imageFileSize = imageFromDbReader["ImageFileSize"].ToString();
               byte[] ImageFileBinaryData = (byte[])imageFromDbReader["Logo"];
                 imageResponse.ContentType = imageFileMIMEType;
                imageResponse.AddHeader("ImageFileSize", imageFileSize);
                BinaryWriter imageFromDbWriter = new BinaryWriter(imageResponse.OutputStream);
              imageFromDbWriter.Write(ImageFileBinaryData, 0, ImageFileBinaryData.Length);
               imageFromDbWriter.Close();

So please help me.

Thank You
Sujith
Posted
Updated 18-Apr-11 21:34pm
v2

1 solution

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