Reputation: 13
I'am trying to fill a picturebox in windows application by using c#. The image path is already saved in the database. How can I display that image on a windows form picture box control ??.
Thanks in advance
Upvotes: 0
Views: 1687
Reputation: 1
For inserting imagepath
into mssqlserver
in C# window application
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();
}
}
Upvotes: 0
Reputation: 283
Hope this is useful for you :)
if (File.Exists(pathFromYourImage) // Just to check if path is valid
{
PictureBox pb1 = new PictureBox();
pb1.Image = System.Drawing.Image.FromFile(pathFromYourImage);
}
Upvotes: 1