-1

// 已经为这样的显示图像编码..

    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);
                }
            }
        }
     }
4

1 回答 1

1

你只需要把while 而不是if

见打击

  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();
        // replace while instead of if in following line
        while(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);
                }
            }
        }
     }
于 2013-10-10T10:35:29.790 回答