【发布时间】:2017-06-08 15:55:17
【问题描述】:
如何使用数据库中的图像路径将图像检索到图片框中?在此之前,我从共享文件夹中检索,但它使我的系统在加载图像时变慢。然后我改变了我想使用存储在 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");
}
}
【问题讨论】:
标签: c# image visual-studio windows-forms-designer