Omid Nosratian
I have problem about insert picture to my SQL database
By Omid Nosratian in SQL Server on Mar 22 2010
  • Rana  Usman
    May, 2010 24

    yeh, of course the picture which u take it should be binary type

    or another way is to link the that picture in ur datatable

    mean save the picture in ur pc and link that location it's easiest way but not proffessional

    • 0
  • vamsi krishna
    Mar, 2010 30

    To Insert the picture first u need to take the picture box and then convert the picture into the memory stream and after that store it into byte[] array and then store into the dataase

    MemorStream ms=new MemoryStream();
    pictureBox1.image.Save(ms,ImageType.JPG);
    byte[] data=new byte[ms.Length);
    int position=0;
    ms.Read(data,0,Convert.ToInt32(ms.Lenght));

    Then Add the Parameter to the data base as
    Cmd.Parameters.addWithKey("@Photo",data);

    • 0
  • aaron ren
    Mar, 2010 24

    it should be binary type

    • 0
  • Omid Nosratian
    Mar, 2010 22

    when i try to insert a picture to the database's table ,occured an exception, the data type of the Picture's field in table of the database is Image .

    the exception occured on this code:

    newRow["Picture"] = pictureBox1.Image;

    and the exception error is:

    Type of value has a mismatch with column typeCouldn't store <System.Drawing.Bitmap> in Picture Column.  Expected type is Byte[].

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS