c #windows应用程序用图像路径存储在数据库中填充图片框

时间:2014-04-02 06:28:44

标签: c# .net picturebox

我正在尝试使用c#填充Windows应用程序中的图片框。图像路径已保存在数据库中。如何在Windows窗体图片框控件上显示该图像??。

提前致谢

2 个答案:

答案 0 :(得分:1)

希望这对你有用:)

if (File.Exists(pathFromYourImage) // Just to check if path is valid
{
    PictureBox pb1 = new PictureBox();
    pb1.Image = System.Drawing.Image.FromFile(pathFromYourImage);
}

答案 1 :(得分:0)

在C#窗口应用程序中将imagepath插入mssqlserver

 private void button1_Click(object sender, EventArgs e) {
     OpenFileDialog open = new OpenFileDialog();
     open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

     if (open.ShowDialog() == DialogResult.OK) {
         pictureBox1.Image = new Bitmap(open.FileName);
         string imgpath = open.FileName;
         con.Open();
         SqlCommand cmd = new SqlCommand("insert into TB_Image values('"+  imgpath+"')", con);
         cmd.ExecuteNonQuery();
         con.Close();
     } 
}