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. 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! 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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.