这是我的代码: 请给我一个解决方案......
ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd = new SqlCeCommand("update register set name='" + textBox1.Text + "' ,address='" + textBox2.Text + "',mobile='" + textBox3.Text + "',gender='" + a + "',dob='" + textBox4.Text + "' ,photo='"+byteArrayToImage(photo_aray)+"',worktype='" + comboBox2.SelectedItem + "',workertype='" + comboBox1.SelectedItem + "',dor='" + textBox5.Text+ "' where name='" + comboBox3.SelectedItem.ToString() + "'", con);
cmd.ExecuteNonQuery();
//convert bytearray to image...
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
答案 0 :(得分:0)
首先,您要使用参数化查询http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlcecommand.parameters(v=vs.100).aspx
其次,"图像"数据库中的类型只意味着"二进制数据"它与.NET中的Image类不同。您希望传递字节数组本身,而不是您的byteArrayToImage()返回的Image。