如何修复“参数无效”。错误消息

时间:2019-05-17 15:34:52

标签: c# sql-server winforms

我需要在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;
}

我收到错误消息:

  

“参数无效。”

我在做什么错了?

0 个答案:

没有答案