简体   繁体   English

数据中继器未显示图像

[英]data repeater not showing image

I need some help please. 我需要一些帮助。 I have used a data repeater to display values from the database, all columns display values in the text boxes on the repeater except for the image. 我使用了数据转发器来显示数据库中的值,除图像外,所有列均在转发器的文本框中显示值。 Am failing to convert byte back to image here's my code for save to database 无法将字节转换回图像这是我的代码以保存到数据库

private void btnSave_Click(object sender, EventArgs e)
{
    byte[] imageBt = null;
    FileStream fstream = new FileStream(this.txtImgPath.Text,FileMode.Open,FileAccess.Read);
    BinaryReader Br = new BinaryReader(fstream);
    imageBt = Br.ReadBytes((int)fstream.Length);
    // byte[] pic = stream.ToArray();
    try
    {
        conDB.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = conDB;
        command.CommandText = "insert into abaanaCC (CCSpn_CODE,CCFname,CCLname,CCMname,CCDOB,CCgender,CCSchool,CaClass,CCVillage,CCSiblings,CCGuardian,CCContact,CCImage)" +
                " values ('" + spn_codetxt.Text + "','" + txtfname.Text + "','" + lnametxt.Text + "','" + mnametxt.Text + "','" + DOBDTPicker1.Text + "','" + gendercomboBox.Text + "','" + schtxt.Text + "','" + classcomboBox.Text + "','" + villatxt.Text + "','" + siblingscombobx.Text + "','" + guardiantxt.Text + "','" + contacttxt.Text + "',@IMG) ";
        command.Parameters.Add(new OleDbParameter("@IMG",imageBt));
        //command.Parameters.AddWithValue("@IMG",pic);
        command.ExecuteNonQuery();
        MessageBox.Show("Record Saved");
    }
    catch (Exception ex)
    {
        MessageBox.Show("Unable to save" + ex);
    }
    conDB.Close();
}

then for the data repeater 然后是数据中继器

private void Update_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'abaanaDataSet.abaanaCC' table. You can move, or remove it, as needed.
        this.abaanaCCTableAdapter.Fill(this.abaanaDataSet.abaanaCC);
        int c = this.abaanaDataSet.abaanaCC.Rows.Count;
        if (c > 0) ;
        {
            byte[] mydata = new byte[0];
            mydata = (byte[])(this.abaanaDataSet.abaanaCC.Rows[c-1]["CCImage"]);
            MemoryStream stream = new MemoryStream(mydata);
            cCImagePictureBox.Image = Image.FromStream(stream);

        }

} }

Make sure you're actually getting valid image data from your dataset. 确保您实际上是从数据集中获取有效的图像数据。 This should work: 这应该工作:

private void Form3_Load(object sender, EventArgs e)
{
    this.productPhotoTableAdapter.Fill(this.adventureWorks2014DataSet.ProductPhoto);

    byte[] mydata = (byte[])this.adventureWorks2014DataSet.ProductPhoto[100]["LargePhoto"];
    MemoryStream stream = new MemoryStream(mydata);
    pictureBox1.Image = Image.FromStream(stream);
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM