1: public static MemoryStream connectDbGetPhoto(string queryParam)
2: {
3: // open a connection to the database
4: SqlConnection dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings[SauConstants.PHOTO_DATABASE].ConnectionString);
5: try
6: {
7: dbCon.Open();
9: StringBuilder query = new StringBuilder(" SELECT Resim from Resimler WHERE UserId = " + queryParam);
10: SqlDataAdapter adapter = new SqlDataAdapter(query.ToString(), dbCon);
11: DataSet ds = new DataSet();
12: adapter.Fill(ds);
13: DataTable dt = new DataTable();
14: dt = ds.Tables[0];
15: byte[] barrImg = (byte[])dt.Rows[0]["Resim"];
16: MemoryStream mstream = new MemoryStream(barrImg);
17: return mstream;
18: }
19: catch (Exception e)
20: {
21: return null;
22: }
23: finally
24: {
25: dbCon.Close();
26: }
27: }
Then the image is loaded to PictureBox component as follows:
1: MemoryStream resim = connectDbGetPhoto(user.ID.ToString());
2: this.picResim.Value = Image.FromStream(resim);
However, if the loaded photograph is too big for the pictureBox, layout problems arise as in http://www.programmersheaven.com/mb/VBasic/322240/322240/display-whole-picture-in-picture-box-or-formplease-help/ To solve this problem:
1: this.picResim.Sizing = ImageSizeMode.ScaleProportional;
By the way, i use http://codeformatter.blogspot.com/ for a while to format my source code and i strongly recommend it!!