Image img = PictureBox1.Image;
byte[] arr;
ImageConverter converter = new ImageConverter();
arr = (byte[])converter.ConvertTo(img, typeof(byte[]));
SqlCommand cmd = new SqlCommand("insert into tblWerknemers2 (Naam,Voornaam,Foto) values(@Naam,@Voornaam@Foto)", con);
cmd.Parameters.AddWithValue("@Naam", txtNaam.Text);
cmd.Parameters.AddWithValue("@Voornaam", txtVoornaam.Text);
cmd.Parameters.AddWithValue("@Foto", arr);
这里我将图像插入数据库,但问题是我不知道如何检索它。以下是我尝试这样做的方法。
SqlDataReader read = command.ExecuteReader();
while (read.Read())
{
txtNaam.Text = (read["Naam"].ToString());
txtVoornaam.Text = (read["Voornaam"].ToString());
arr = (byte[])read["Foto"];
}
read.Close();
答案 0 :(得分:0)
byte[] arr = (byte[])read["Foto"];
if (arr.Length > 0)
{
MemoryStream mem = new MemoryStream(arr);
PictureBox1.Image = Image.FromStream(mem);
}