Want to save image to DB

Discussion in 'C#' started by ranacseruet, Oct 4, 2009.

  1. #1
    Hi all,
    I want help on saving image to acccess database using asp.net/c#. i can get the inputstream/byte array of the image posted, but now confused about how to write the query to insert this image. Can anyone plz help?

    Regards
     
    ranacseruet, Oct 4, 2009 IP
  2. rahulwb

    rahulwb Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1. Add at the top of class
    using System.Data.OleDb;

    2. Use following code


    protected void saveimage(Byte _image)
    {
    OleDbConnection _conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\msaccessname.mdb;");
    //replace Images with table name and columnName with column where u want to store image
    String _cmdstr = "INSERT INTO Images (columnName) VALUES @img";
    OleDbCommand _cmd = new OleDbCommand(_cmdstr, _conn);

    try
    {
    _cmd.Parameters.AddWithValue("@img", _image);

    using (_conn)
    {
    _cmd.ExecuteNonQuery();
    }
    }
    catch(Exception ex)
    {
    throw ex;
    }
    }
     
    rahulwb, Oct 5, 2009 IP
  3. ranacseruet

    ranacseruet Peon

    Messages:
    302
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi, thanks for your help. I got it functional :)
     
    ranacseruet, Oct 6, 2009 IP
  4. jainsumit

    jainsumit Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks For Share I also Have Same Problem. but now I got Solution....
     
    jainsumit, Oct 24, 2009 IP