Loading PictureBox Image From Database

后端 未结 3 2086
逝去的感伤
逝去的感伤 2020-12-03 22:18

i\'m trying to load images from database to a PictureBox. I use these following codes in order to load them to my picture. I\'ve written some code but don\'t kn

3条回答
  •  时光说笑
    2020-12-03 22:38

    private void btnShowImage_Click(object sender, EventArgs e)
    {
        string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
        Con = new OleDbConnection(@constr);
        Con.Open();
        Com = new OleDbCommand();
        Com.Connection = Con;     
        Com.CommandText = "SELECT Photo FROM PatientImages WHERE Patient_Id =  " + val + " ";
        OleDbDataReader reader = Com.ExecuteReader();
        if (reader.Read())
        {
            byte[] picbyte = reader["Photo"] as byte[] ?? null;
            if (picbyte != null)
            {
                MemoryStream mstream = new MemoryStream(picbyte);
                pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
            {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
        }
    }
    

提交回复
热议问题