Image with OleDB

Last post 05-03-2007 10:16 PM by Jessica Cao - MSFT. 2 replies.

Sort Posts:

  • Image with OleDB

    05-02-2007, 1:08 PM
    • Member
      point Member
    • nc3b
    • Member since 05-02-2007, 5:06 PM
    • Posts 1
    Hello, I want to display an image stored in an access database, please show me a way of doing this. I have been looking for a working example for days, but I can't find any.
  • Re: Image with OleDB

    05-02-2007, 4:14 PM
    Answer
    • Contributor
      2,507 point Contributor
    • omerkamal
    • Member since 02-06-2006, 2:47 PM
    • Germany
    • Posts 513

    We have some Tutorials on the Image saving and retrieving on our website.

    visit this:

    http://dotnet-friends.com/Articles/ASP/ARTinASP27c1c67b-0483-4d8d-9fca-86d066d03aa7.aspx

    They are implemented with SQL Database. But querying the Accees data wont vary much.

    did it help?

  • Re: Image with OleDB

    05-03-2007, 10:16 PM
    Answer

    Hello,

    Here is the sample code for  display an image stored in SQL Server, but I think you can change a little to make it work for Access

      protected void Button2_Click(object sender, EventArgs e)
        {
            string connect = "Data Source=localhost\\sqlexpress;Integrated Security=True;Initial Catalog=pubs";
            System.Data.SqlClient.SqlConnection sqlconnect = new System.Data.SqlClient.SqlConnection(connect);
            string command = "select * from image";
            System.Data.SqlClient.SqlCommand sqlcommand = new System.Data.SqlClient.SqlCommand();
            sqlcommand.CommandText = command;
            sqlcommand.Connection = sqlconnect;

            System.Data.SqlClient.SqlDataReader dr;
            sqlconnect.Open();
            dr = sqlcommand.ExecuteReader();
            while (dr.Read())
            {
                Response.Clear();
            
                Response.ClearHeaders();
            
                Response.ContentType = dr[1].ToString();
                Response.AddHeader("content-disposition", "form-data;filename="+dr[2].ToString()+")");

                Response.BinaryWrite((byte[])dr[0]);
                Response.Flush();
                Response.End();
            }
            sqlconnect.Close();

        }

    Hope it helps,

    Jessica

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Page 1 of 1 (3 items)