locked
Read and write image to dataBase RRS feed

  • Question

  • User1603713763 posted

    hi

    i need vb code how to read and write an image to access data base

     

    how to read it from dataTable object and store it in my application as image object

     

    thanx in advance 

    Monday, August 2, 2010 4:28 AM

Answers

  • User275991403 posted

    Hi,

    using System.Data.OleDb;

    OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0

     

    using System.IO;

    IO is used to create the memory stream variable that can store the binary format of the image content.

     

    C# Code to Upload Image to MS Access Database:

     

    int imageSize;

    string imageType;

    Stream imageStream;

    // Gets the Size of the Image

    imageSize = fileImgUpload.PostedFile.ContentLength;

     

    // Gets the Image Type

    imageType = fileImgUpload.PostedFile.ContentType;

     

    // Reads the Image stream

    imageStream = fileImgUpload.PostedFile.InputStream;

     

    byte[] imageContent = new byte[imageSize]; int intStatus;

    intStatus = imageStream.Read(imageContent, 0, imageSize);

     

    Connection string to connect the ASP.Net 2.0 web application with MS Access Database:

     

    // Access Database oledb connection string

    // Using Provider Microsoft.Jet.OLEDB.4.0

    String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");



    otherwise use the following link:

    http://programming.top54u.com/post/Store-and-Display-Images-from-MS-Access-Database-Using-C-Sharp.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 2, 2010 6:53 AM

All replies

  • User275991403 posted

    Hi,

    using System.Data.OleDb;

    OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0

     

    using System.IO;

    IO is used to create the memory stream variable that can store the binary format of the image content.

     

    C# Code to Upload Image to MS Access Database:

     

    int imageSize;

    string imageType;

    Stream imageStream;

    // Gets the Size of the Image

    imageSize = fileImgUpload.PostedFile.ContentLength;

     

    // Gets the Image Type

    imageType = fileImgUpload.PostedFile.ContentType;

     

    // Reads the Image stream

    imageStream = fileImgUpload.PostedFile.InputStream;

     

    byte[] imageContent = new byte[imageSize]; int intStatus;

    intStatus = imageStream.Read(imageContent, 0, imageSize);

     

    Connection string to connect the ASP.Net 2.0 web application with MS Access Database:

     

    // Access Database oledb connection string

    // Using Provider Microsoft.Jet.OLEDB.4.0

    String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");



    otherwise use the following link:

    http://programming.top54u.com/post/Store-and-Display-Images-from-MS-Access-Database-Using-C-Sharp.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 2, 2010 6:53 AM