locked
How to get OLE object from access database and display in the form view? RRS feed

  • Question

  • User-1306803474 posted
    I have no idea why it cannot show the picture that i put inside the access database. I set the type of the field is OLE object and put BITmap file in it. My source code in my webpage is <asp:TextBox ID="Book_PictureTextBox" runat="server" Text='<%# Bind("[Book Picture]") %>' /> And it will display these word if i try to run the webpage Book Picture: System.Byte[] So, i was wondering. Is it change the Text to something like "img" tags or something else. I need help please. Thanks. kekewong
    Thursday, November 20, 2008 12:37 PM

Answers

  • User-821857111 posted

    First, I would never store images in an Access database.  You will get horrible performance at best. Store the file name in the database instead. Secondly, web browsers are only able to handle .jpg, .gif and .png image file types.  You do need an <img> tag to display a picture (or and ASP.NET Image control).

    This tutorial should get you started: http://www.maconstateit.net/tutorials/ASPNET20/ASPNET04/aspnet04-03.aspx and there are more here: http://www.maconstateit.net/tutorials/ASPNET20/default.htm

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:30 PM
  • User-1199946673 posted

    create a empty webform, and put the following in the code_behind file (of course don't forget to change the field and tablename!): 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Using myConnection As New System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Dim SQL As String = "SELECT [imageField] FROM [tablename]"
    Using myCommand As New System.Data.OleDb.OleDbCommand(SQL, myConnection)
    myConnection.Open()
    Using myReader As System.Data.OleDb.OleDbDataReader = myCommand.ExecuteReader
    If myReader.Read Then
    Response.ContentType = "image/bmp"
    Response.BinaryWrite(myReader("imageField"))
    End If
    End Using
    End Using
    End Using

    End Sub

    You can show the picture with (I called the file above image.aspx and placed it in the images folder!)

    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/image.aspx" />

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:31 PM

All replies

  • User-821857111 posted

    First, I would never store images in an Access database.  You will get horrible performance at best. Store the file name in the database instead. Secondly, web browsers are only able to handle .jpg, .gif and .png image file types.  You do need an <img> tag to display a picture (or and ASP.NET Image control).

    This tutorial should get you started: http://www.maconstateit.net/tutorials/ASPNET20/ASPNET04/aspnet04-03.aspx and there are more here: http://www.maconstateit.net/tutorials/ASPNET20/default.htm

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:30 PM
  • User-1199946673 posted

    create a empty webform, and put the following in the code_behind file (of course don't forget to change the field and tablename!): 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Using myConnection As New System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Dim SQL As String = "SELECT [imageField] FROM [tablename]"
    Using myCommand As New System.Data.OleDb.OleDbCommand(SQL, myConnection)
    myConnection.Open()
    Using myReader As System.Data.OleDb.OleDbDataReader = myCommand.ExecuteReader
    If myReader.Read Then
    Response.ContentType = "image/bmp"
    Response.BinaryWrite(myReader("imageField"))
    End If
    End Using
    End Using
    End Using

    End Sub

    You can show the picture with (I called the file above image.aspx and placed it in the images folder!)

    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/image.aspx" />

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:31 PM