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

时间:2017-06-08 07:43:38

标签: c# image visual-studio windows-forms-designer

如何使用数据库中的图像路径将图像检索到图片框?在此之前我从共享文件夹中检索但是在加载图像时它使我的系统变慢。然后我改变了我想要使用存储在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");
                        }
                    }

1 个答案:

答案 0 :(得分:0)

pictureBox1.Image = Image.FromFile("" + read [" path"]。ToString());

            pictureBox1.SizeMode=System.Windows.Forms.PictureBoxSizeMode.StretchImage;