我正在尝试将图像从数据库加载到PictureBox.我使用以下代码加载我们的照片.我写了一些代码,但不知道我应该做什么来继续.
任何帮助将不胜感激.
private void button1_Click(object sender,EventArgs e) { sql = new sqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Test;Integrated Security=True"); cmd = new sqlCommand(); cmd.Connection = sql; cmd.CommandText = ("select Image from Entry where EntryID =@EntryID"); cmd.Parameters.AddWithValue("@EntryID",Convert.ToInt32(textBox1.Text)); }
解决方法
在button1_Click中继续执行此操作:
// your code first here.. var da = new sqlDataAdapter(cmd); var ds = new DataSet(); da.Fill(ds,"Images"); int count = ds.Tables["Images"].Rows.Count; if (count > 0) { var data = (Byte[])(ds.Tables["Images"].Rows[count - 1]["Image"]); var stream = new MemoryStream(data); pictureBox1.Image= Image.FromStream(sream); }