I'm trying to retrieve data from my database and set it to textbox and picture box using text change.
Here is my code:
private void textBox1_TextChanged(object sender, EventArgs e)
{
string sqlstring = "database = db_phonebook; user = root; password = ''; server = 'localhost'; SSL Mode = None";
MySqlConnection mysqlcon = new MySqlConnection(sqlstring);
MySqlCommand mysqlcom;
MySqlDataReader mdr;
mysqlcon.Open();
string selectquery = ("SELECT* FROM tbl_phonebook WHERE CID LIKE '" + this.textBox1.Text + "%'");
mysqlcom = new MySqlCommand(selectquery, mysqlcon);
mdr = mysqlcom.ExecuteReader();
if (mdr.Read())
{
cid.Text = mdr.GetString("CID");
name.Text = mdr.GetString("Name");
address.Text = mdr.GetString("Address");
contact.Text = mdr.GetString("Contact_Number");
email.Text = mdr.GetString("Email_Address");
photobox.Image = mdr.("Photo"); /// this line is the error it says "cannot implicitly convert type 'string' to 'System.Drawing.Imaging'
}
else
{
MessageBox.Show("Record Not Found!");
}
mysqlcon.Close();
}
how do I fix "cannot implicitly convert type 'string' to 'System.Drawing.Imaging' or is there another way to display image from database in picture box
Assuming that your
photoboxobject is aPictureBoxand that your database stores a link or path to your image, instead of setting the .Image property call its Load method which will set the Image location and load it: