1
注意:这是Windows应用程序,sql server作为数据库ado.net。如何在datagridview中保存图像流
我暂时在datagridview中插入图像,然后遍历它们并将每一行保存在数据库中。 我知道如何从图片框插入流这样
MemoryStream stream = new MemoryStream();
pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = stream.ToArray();
SqlCommand cmda = new SqlCommand("INSERT INTO KeyWord (ItemName, DateEntry,image, imageindex) VALUES (N'" + listBoxI.ToString() + "', GETDATE(), @image, 1)", cn);
cmda.Parameters.AddWithValue("@Pic", pic);
try
{
cn.Open();
cmda.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
我想dataGridView1.Rows[x].Cells[1].Value
我的问题是如何从DataGridView保存图像替换pictureBox1
?
'Cells [1]'是一个'DataGridViewImageColumn'吗? – etaiso
@etaiso是的,它是 –