I use Windows Form and MySQL for my project. In this I want to save the image and get it.
I created a table called 'image' in which
CREATE TABLE `image` ( `id` INT(15) NOT NULL AUTO_INCREMENT, `extension` VARCHAR(50) NOT NULL, `image` LONGBLOB NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM ROW_FORMAT=DEFAULT AUTO_INCREMENT=2
AND
OpenFileDialog open = new OpenFileDialog(); // image filters open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png"; if (open.ShowDialog() == DialogResult.OK) { txt_imagePath.Text = open.FileName; } hp.getConnStr(); try { MySqlConnection connection = new MySqlConnection(hp.myConnStr); MySqlCommand command = connection.CreateCommand(); command.CommandText = "insert into image (image) values ('"+txt_imagePath.Text +"')"; command.Connection.Open(); command.ExecuteNonQuery(); command.Connection.Close(); }
in the event of clicking on the "Browse" button, ..
File saved successfully. Now I want to get this photo and show in the image window. So I try this code below, ..
MySqlConnection connection = new MySqlConnection(hp.myConnStr); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; command.CommandText = "select image from image"; connection.Open(); Reader = command.ExecuteReader(); while (Reader.Read()) { pictureBox1.Image = new Bitmap(Reader[0].ToString()); } connection.Close();
but not used.
Please help me.
source share