locked
Image not displaying inDetailsView Control RRS feed

  • Question

  • User-1473011517 posted

    Hi,

    Help again.

    I m using Access DataBase and in which I have stored one image in first row in "Pic" column and Data type of that column is "OLE Object". In DetailsView I m using <asp:ImageField/> control to display image. When the page is loaded the DetailsView fills with data but image is not displaying

    <asp:ImageField DataFieldUrl="Pic" HeaderText="Photo"><asp:ImageField>



    Monday, September 19, 2016 8:51 AM

Answers

  • User36583972 posted

    Hi vijaypwr61,

    Thank you but I have to store the images more than 800 so I used access database.

    You can extract the content (OLE Object) to images and store images on your filesystem. The following code for your reference.

                String strConn = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Nwind.mdb;";
                OleDbConnection conn = new OleDbConnection(strConn);
                Byte[] byPicture;
                String strCmd = "Select Pic From Categories where ID=001";
                OleDbCommand cmd = new OleDbCommand(strCmd, conn);
                try
                {
                    conn.Open();
                    byPicture = (Byte[]) cmd.ExecuteScalar();
                    conn.Close();
                    MemoryStream ms = new MemoryStream();
                    Bitmap bm;
                    ms.Write(byPicture, 78, byPicture.Length - 78);
                    bm = new Bitmap(ms);
                    String strPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.jpg";
                    bm.Save(strPath, ImageFormat.Jpeg);
                }
                catch
                {
                    
                }
    
    

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 20, 2016 9:36 AM

All replies

  • User36583972 posted

    Hi vijaypwr61,

    As far as I know, the 'OLE Object' datatype in access can store any binary data including images/files. But Images whose URL is determined by database data can be displayed in the GridView or DetailsView using the ImageField. The ImageField contains DataImageUrlField and DataImageUrlFormatString properties that work like the HyperLinkField s DataNavigateUrlFields and DataNavigateUrlFormatString properties.

    So, I would suggest you to store images on filesystem and only save the names/paths in a 'text' field in access.

    You can refer the following link.

    Displaying Binary Data in the Data Web Controls:

    http://www.asp.net/web-forms/overview/data-access/working-with-binary-files/displaying-binary-data-in-the-data-web-controls-vb

    Best Regards,

    Yohann Lu

    Tuesday, September 20, 2016 7:28 AM
  • User-1473011517 posted

    Thank you but I have to store the images more than 800 so I used access database.

    Tuesday, September 20, 2016 8:01 AM
  • User36583972 posted

    Hi vijaypwr61,

    Thank you but I have to store the images more than 800 so I used access database.

    You can extract the content (OLE Object) to images and store images on your filesystem. The following code for your reference.

                String strConn = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Nwind.mdb;";
                OleDbConnection conn = new OleDbConnection(strConn);
                Byte[] byPicture;
                String strCmd = "Select Pic From Categories where ID=001";
                OleDbCommand cmd = new OleDbCommand(strCmd, conn);
                try
                {
                    conn.Open();
                    byPicture = (Byte[]) cmd.ExecuteScalar();
                    conn.Close();
                    MemoryStream ms = new MemoryStream();
                    Bitmap bm;
                    ms.Write(byPicture, 78, byPicture.Length - 78);
                    bm = new Bitmap(ms);
                    String strPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.jpg";
                    bm.Save(strPath, ImageFormat.Jpeg);
                }
                catch
                {
                    
                }
    
    

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 20, 2016 9:36 AM
  • User-1473011517 posted

    Thank youLaughing

    Thursday, September 22, 2016 10:41 AM