我需要在winforms PictureBox
中显示来自MSSQL数据库的图像。
运行代码时
try
{
OleDbConnection myConnection = new OleDbConnection("File Name = mylink.udl");
myConnection.Open();
OleDbCommand cmd = new OleDbCommand("SELECT Stu_Name,Photo FROM stu_Details WHERE Stu_ID ='" + stuid + "'", myConnection);
var da = new OleDbDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds, "Photo");
int count = ds.Tables["Photo"].Rows.Count;
if (count > 0)
{
var data = (Byte[])ds.Tables["Photo"].Rows[count - 1]["Photo"];
var stream = new MemoryStream(data);
pictureBox2.Image = Image.FromStream(stream);
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
我收到错误消息:
“参数无效。”
我在做什么错了?