简体   繁体   English

(已解决)无法将“system.byte”类型的 object 转换为“system.string”类型(组合框填充 PictureBox)

[英](Solved) unable to cast object of type 'system.byte ' to type 'system.string' (combobox populate PictureBox)

and sorry for the inconvenience.对给您带来的不便深表歉意。 I hope you can help me, I have this code.我希望你能帮助我,我有这个代码。 which by selecting a combobox populates a series of textboxes, Now I would like to make sure to add, in addition to the textbox, also a picturebox.通过选择 combobox 填充一系列文本框,现在我想确保除了文本框之外还添加一个图片框。 but I get the error as per the title?但我得到了标题中的错误? How can I proceed.我该如何继续。 Here is the code.这是代码。 Thanks everyone for the help.感谢大家的帮助。

// STRINGA CHE PERMETTE DALLA COMBOBOX VIA DI DETERMINARE IL REFERENTE
    private void cboVia_SelectedIndexChanged(object sender, EventArgs e)
    {
        string str = constring;
        SqlConnection con2 = new SqlConnection(str);
        string query = "SELECT Referenti.IDReferenti, Referenti.CognomeRF, Referenti.NomeRF, Referenti.ZonaRF, Referenti.LinkRF, Referenti.CodiceFotoRF, Referenti.TelefonoRF, Referenti.EmailRF, Referenti.ImageRF, Vie.Settore, Vie.Zona, Vie.Via FROM  Referenti FULL OUTER JOIN  Vie ON Referenti.ZonaRF = Vie.Zona where Via = '" + cboVia.Text + "'";
        SqlCommand cmd = new SqlCommand(query, con2);
        SqlDataReader dbr;
        try
        {

            con2.Open();

            dbr = cmd.ExecuteReader();
            while (dbr.Read())
            {
                //string sID = (string)dbr["IDReferenti"].ToString();
                string CognomeReferente = (string)dbr["CognomeRF"]; // name is string value
                string NomeReferente = (string)dbr["NomeRF"];
                string ZonaReferente = (string)dbr["ZonaRF"];
                string EmailReferente = (string)dbr["EmailRF"];
                string CodiceFotoReferente = (string)dbr["CodiceFotoRF"];
                string imageRF = (string)dbr["ImageRF"];
                //txtID.Text = sID;
                txtCognomeReferente.Text = CognomeReferente;
                txtnomeReferente.Text = NomeReferente;
                txtEmailReferente.Text = EmailReferente;
                txtZona.Text = ZonaReferente;
                txtcodiceFotoReferente.Text = CodiceFotoReferente;
                // PICTUREBOX
                imageRFPictureBox.ImageLocation = imageRF;
                //PICTUREBOX
            }
        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Errore");
        }
    }
    // FINE STRINGA CHE PERMETTE ALLA COMBOBOX VIA DI DETERMINARE IL REFERENTE

@SeanSkelly thanks! @SeanSkelly 谢谢! Thanks to your advice maybe I found the solution!感谢您的建议,也许我找到了解决方案!

byte[] imageRF = (byte[])dbr["ImageRF"];
if (imageRF == null)
                {
                    imageRFPictureBox.Image = null;
                }
                else
                {
                    MemoryStream mstream = new MemoryStream(imageRF);

                    imageRFPictureBox.Image = System.Drawing.Image.FromStream(mstream);
                }

            }
        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Errore");
        }

暂无
暂无

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

相关问题 无法将类型为“ System.Byte”的对象转换为类型为“ System.String”的对象 - Unable to cast object of type 'System.Byte' to type 'System.String' 无法将类型为“ System.String”的对象转换为类型为“ System.Byte []”的对象。 发布后发生错误 - Unable to cast object of type 'System.String' to type 'System.Byte[]'. Error after publish 无法将类型为“ System.Byte []”的对象转换为类型为“ System.String []”的对象 - Unable to cast object of type 'System.Byte[]' to type 'System.String[]' Linq-收到错误“无法将类型为“ System.String”的对象转换为类型为“ System.Byte []”。” - Linq - Receiving error “Unable to cast object of type 'System.String' to type 'System.Byte[]'.” 无法将类型为“System.String”的 object 转换为类型“System.Byte []”错误 MYSQL NET CORE 3.1 - Unable to cast object of type 'System.String' to type 'System.Byte[]' Error MYSQL NET CORE 3.1 无法将“System.Byte”类型的 object 转换为“System.String”类型。 - Unable to cast object of type 'System.Byte' to type 'System.String'.' 从数据库读取数据导致无法将类型为“ System.Byte”的对象转换为类型为“ System.String”的错误 - Reading data from database gives Unable to cast object of type 'System.Byte' to type 'System.String' error 无法将System.string强制转换为System.Byte [] - Unable to cast System.string to System.Byte[] 反序列化对象时,无法将类型为System.String的对象转换为类型为System.Byte [] - Cannot convert object of type System.String to type System.Byte[] when deserializing object 无法转换类型为system.int32的对象以从数据库中键入system.string组合框填充 - unable to cast object of type system.int32 to type system.string combobox fill from database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM