I have created a form in which there are various values such as Name, Address, Date of Birth etc. The user is also allowed to select an image in a picture box.
I want to insert these values along with the Image into database in appropriate columns.
Any help is appreciated

Member Avatar
private void contactPhoto_DoubleClick(object sender, EventArgs e)
            if (contactPhotoBrowse.ShowDialog() == DialogResult.OK && contactPhotoBrowse.FileName.Length > 0)
                // put image to db
                System.IO.FileStream fileStream = System.IO.File.Open(contactPhotoBrowse.FileName.ToString(), System.IO.FileMode.Open);
                byte[] fileData = new byte[fileStream.Length];
                fileStream.Read(fileData, 0,  (int)fileStream.Length);
                if (Definitions.sqlConnection.State == ConnectionState.Closed)

                Definitions.sqlCommand = new SqlCeCommand("insert into Contacts_Photo (Photo, ContactID) values (?," + Convert.ToInt32(contactList.FocusedItem.Tag.ToString()) + ")", Definitions.sqlConnection);
                SqlCeParameter image = new SqlCeParameter("Photo", SqlDbType.Image);
                image.Value = fileData;
                Definitions.sqlCommand = null;

                // read image from db
                Definitions.sqlCommand = new SqlCeCommand("select Photo from Contacts_Photo where ContactID=" + Convert.ToInt32(contactList.FocusedItem.Tag.ToString()), Definitions.sqlConnection);
                byte[] value = (byte[])Definitions.sqlCommand.ExecuteScalar();
                MemoryStream ms = new MemoryStream(value);
                contactPhoto.Image = (Bitmap)Bitmap.FromStream(ms);