我正在尝试从我的数据库中检索数据并使用文本更改将其设置为文本框和图片框。
这是我的代码:
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();
}
如何修复“无法将类型'string'隐式转换为'System.Drawing.Imaging'或者是否有另一种方法可以在图片框中显示来自数据库的图像