MySqlConnection conn = new MySqlConnection("SERVER=localhost; DATABASE=test ;UID=root;PASSWORD=12345");
MySqlCommand command;
private void button4_Click(object sender, EventArgs e)
{
try
{
string sql = "SELECT fn,ln,file FROM test2 WHERE id=" + textBox1.Text + "";
if (conn.State != ConnectionState.Open)
conn.Open();
command = new MySqlCommand(sql, conn);
MySqlDataReader reader = command.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
textBox2.Text = reader[0].ToString();
textBox3.Text = reader[1].ToString();
byte[] img = (byte[])(reader[2]);
if (img == null)
pictureBox1.Image = null;
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(ms);
}
}
else
{
MessageBox.Show("Статья не существует");
}
conn.Close();
}
catch (Exception ex)
{
conn.Close();
MessageBox.Show(ex.Message);
}
}