我正在使用以下代码向用户检索图像和其他信息。我还想在图像下方的文本框中显示图像文件路径。我一直在尝试这样做,但没有成功。
以下是我编写的代码,除了从 mysql display 获取图像位置外,我还有其他事情要做。
请任何人帮助我!
private void showData_Click(object sender, EventArgs e)
{
string myConnection = "datasource = localhost; port=3306; username=root; password=root";
string Query = "select * from MawkMo.Enlist_info;";
MySqlConnection sqlConnection = new MySqlConnection(myConnection);
MySqlCommand sqlCommand = new MySqlCommand(Query, sqlConnection);
MySqlDataReader myReader;
try
{
sqlConnection.Open();
myReader = sqlCommand.ExecuteReader();
while (myReader.Read())
{
byte[] imgbyte = (byte[])(myReader["Photo"]);
if (imgbyte == null)
{
PhotoBox.Image = null;
}
else
{
//string imgPath = (string)sqlCommand.ExecuteScalar();
//Photo_path.Text = imgPath;
MemoryStream mryStream = new MemoryStream(imgbyte);
PhotoBox.Image = System.Drawing.Image.FromStream(mryStream);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}