4
Reply

I have problem about insert picture to my SQL database

    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

    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);

    it should be binary type

    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[].