次のコードを使用して、画像やその他の情報をユーザーに取得しています。画像の下のテキストボックスに画像ファイルのパスも表示したいと思います。私は成功せずにそれをやろうとしてきました。
以下は私が書いたコードです.mysqlディスプレイから画像の場所を取得することを除いて、他の問題を解決しています.
誰か私を助けてください!
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);
}