大众信息网

c#中将保存在数据库中的照片到picturebox,显示参数无效

关注:274  答案:1  手机版
解决时间 2021-01-10 19:24
string Str;
Str = "select eimage from employee where eno = " + u.Name;
conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=apply_for_adminination;Integrated Security=True");
conn.Open();
cmd = new SqlCommand(Str, conn);

byte[] bytt = (byte[])cmd.ExecuteScalar();
if (bytt != null)
{
MemoryStream ms = new MemoryStream(bytt);
this.pictureBox1.Image = Image.FromStream(ms);
}
else
MessageBox.Show("未查询到图片");



最佳答案
我看了一下你的代码,大概只能找到一个错误,你这个参数无效是哪一行抛出的?
Str = "select eimage from employee where eno = " + u.Name;改成
Str = "select eimage from employee where eno = '" + u.Name + "'";
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!