如何在c#中显示数据库中的图像

时间:2015-10-09 06:23:03

标签: c# .net image

如何在c#中显示数据库中的图像。我收到以下错误: -

  

参数无效

 private void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            Utilities.ClearControls(gbxMain);
            AssociateID = 0;
            MainModuleBO objMainModuleBO = new MainModuleBO();
            string[] strReturnValue;

            DataTable dtSearch = objMainModuleBO.GetSearchData(this.MasterFormId);

            DataGridViewColumnPropertiesCollection objDataGridViewColumnPropertiesCollection = new DataGridViewColumnPropertiesCollection();
            objDataGridViewColumnPropertiesCollection.Add(MSTAssociateMasterTO.ASSOCIATEID, "Associate Id", MSTAssociateMasterTO.ASSOCIATEID, true, true, 100);
            objDataGridViewColumnPropertiesCollection.Add(MSTAssociateMasterTO.ASSOCIATENAME, "Associate Name", MSTAssociateMasterTO.ASSOCIATENAME, true, false, 500);

            frmSearch objfrmSearch = new frmSearch();
            objfrmSearch.dtSearch = dtSearch;
            objfrmSearch.objDataGridViewColumnPropertiesCollection = objDataGridViewColumnPropertiesCollection;
            objfrmSearch.ShowDialog();
            strReturnValue = objfrmSearch.strReturnValue;

            if (strReturnValue.Length > 0)
            {
                MSTAssociateMasterBO objMSTAssociateMasterBO = new MSTAssociateMasterBO();
                DataTable dt = objMSTAssociateMasterBO.SelectDataById(Utilities.TextToInt(strReturnValue[0]));
                AssociateID = Utilities.TextToInt(strReturnValue[0]);
                Utilities.BindFormData(this, dt);
                pictureBox1.Image = null;
                foreach (DataRow dr1 in dt.Rows)
                {
                  picbyte = (byte[])dr1["AssociateImageData"];
                  MemoryStream ms = new MemoryStream(picbyte);
                  pictureBox1.Image = Bitmap.FromStream(ms); // here is error occure
                }

                Utilities.EnableDisableControls(gbxMain, false);
                Utilities.EnableDisableButtons(this, CustomControls.ButtonEvent.SearchClick);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);// (this.Controls.Find("txtName", true)[0].GetType().ToString());
        }
    }

0 个答案:

没有答案