C# 如何使用数据库中的图像路径将图像显示到图片框中

C# 如何使用数据库中的图像路径将图像显示到图片框中,c#,image,visual-studio,windows-forms-designer,C#,Image,Visual Studio,Windows Forms Designer,如何使用数据库中的图像路径将图像检索到图片框中?在此之前,我从共享文件夹中检索,但它会使我的系统在加载图像时变慢。然后,我改变了使用MSSQL数据库中存储的图像路径将图像检索到图片框中的方法。希望它不会减慢我的系统。任何人都可以帮助我。这是我的代码,但不是检索图像的工作 private void textBoxEmplNo_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter)

如何使用数据库中的图像路径将图像检索到图片框中?在此之前,我从共享文件夹中检索,但它会使我的系统在加载图像时变慢。然后,我改变了使用MSSQL数据库中存储的图像路径将图像检索到图片框中的方法。希望它不会减慢我的系统。任何人都可以帮助我。这是我的代码,但不是检索图像的工作

private void textBoxEmplNo_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            if (textBoxEmplNo.Text != "")
            {

                string selectSql = "select a.name, a.empno, a.workno, a.icnum, a.passport, a.deptno, a.section, a.designation, b.path from m_employee a inner join m_emp_photo b on b.empno=a.empno where a.empno= @empno";

                SqlCommand cmd = new SqlCommand(selectSql, con);

                cmd.Parameters.AddWithValue("@empno", textBoxEmplNo.Text);

                bool isDataFound = false;

                try
                {

                    con.Open();

                    using (SqlDataReader read = cmd.ExecuteReader())
                    {
                        while (read.Read())
                        {
                            isDataFound = true;

                            textBoxWorkNo.Text = (read["workno"].ToString());
                            textBoxName.Text = (read["name"].ToString());
                            textBoxICPass.Text = (read["icnum"].ToString());
                            textBoxPassport.Text = (read["passport"].ToString());
                            textBoxDept.Text = (read["deptno"].ToString());
                            textBoxSection.Text = (read["section"].ToString());
                            textBoxDesignation.Text = (read["designation"].ToString());

                            pictureBox1.Image = Image.FromFile("@path");
                        }
                    }

pictureBox1.Image=Image.FromFile(“+read[“path”].ToString())


您能否解释一下您的解决方案所做的工作,而不仅仅是粘贴一段代码。祝@Miza;)成功@谢谢。现在我遇到了一些问题,若数据库中并没有图像路径,那个么对于员工的详细信息,就会显示“并没有找到结果”。我怎样才能解决它?我想要找不到图像的地方,其他文本框仍然从数据库中获取值:(如果(String.IsNullOrEmpty(pictureBox1.Image)){pictureBox1.Image=“未找到结果”}请试试@Miza@CagdasBsn这不是我想要的。我已经尝试了您以前的方法来加载图像及其工作。但我有一个问题,即如果数据库中没有图像路径,它在所有文本框中都不会显示结果。我希望其他文本框仍然获得值,即使图像路径在数据库中没有。
            pictureBox1.SizeMode=System.Windows.Forms.PictureBoxSizeMode.StretchImage;