我想从数据库中检索数据。当我更改我的代码以使其显示参数无效时。
private void button7_Click(object sender, EventArgs e)
{
ProductDetails.Items.Clear();
SqlConnection con = new SqlConnection(@"server=xxx-PC; database= sample; integrated security= true");
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblproduct where prodname like '" + textBox1.Text + "%';", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
byte[]imgg =(byte[])(dr["image"]);
if(imgg==null)
pictureBox1.Image= null;
else
{ //i m not getting error it says parameter not valid below//
MemoryStream mstream = new MemoryStream(imgg);
pictureBox1.Image = System.Drawing.Image.FromStream(mstream);
}
ProductDetails.Items.Add(dr[0].ToString() + " \t" + dr[1].ToString() + "\t" + dr[2].ToString()+ dr[3].ToString());
}
}
从 OP 的评论中添加
加载我使用这个代码
byte[] imagebt = null;
FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imagebt = br.ReadBytes((int)fstream.Length);