Retrieving image from DB and to convert byte array value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • velmani
    New Member
    • Mar 2008
    • 1

    Retrieving image from DB and to convert byte array value

    hi ,
    i have problem with Retrieving image from DB
    i have a table with image datatype
    i store a file by using code as follows
    --------------------------------------------------
    string strType;
    int intLength,intSt atus;
    Stream ipStream;
    intLength = File1.PostedFil e.ContentLength ;
    strType = File1.PostedFil e.ContentType;
    byte []imgContent = new byte[intLength];
    ipStream = File1.PostedFil e.InputStream;
    intStatus = ipStream.Read(i mgContent, 0, intLength);
    SqlCommand cmd = new SqlCommand("sp_ insert_image", connection);
    cmd.Parameters. Add("@pname", SqlDbType.Image ).Value = imgContent;
    cmd.Parameters. Add("@type", SqlDbType.VarCh ar).Value = strType;
    cmd.CommandType = CommandType.Sto redProcedure;
    connection.Open ();
    cmd.ExecuteNonQ uery()
    ----------------------------------
    it inserted into db.

    but ,

    while reading from db,table value in dataset like as follows

    SqlDataAdapter da = new SqlDataAdapter( "select pname,type from img_tab ",con);
    DataSet ds = new DataSet();
    da.Fill(ds);

    pname
    ---------
    System.Byte[] ---------> it doesnt retrieve binary value.
    --------------------------------

    problem 2
    ---------------
    SqlDataReader dr = cmd.ExecuteRead er();
    while (dr.Read())
    {
    Response.Conten tType = dr["type"].ToString();
    Response.Binary Write(dr["pname"]); in this line error
    }

    Error 2 Argument '1': cannot convert from 'object' to 'byte[]' D:\velu\Image\r eadrealimage.as px.cs 30 34 D:\velu\Image\

    Error 1 The best overloaded method match for 'System.Web.Htt pResponse.Binar yWrite(byte[])' has some invalid arguments D:\velu\Image\r eadrealimage.as px.cs 30 13 D:\velu\Image\

    so Help me to identify this
Working...