C # -Inserting images in a database

1

I am making a product registration. I can insert the image however when I use a comboBox to make all the data appear the image appears cut in half.

Here is the code for the insert button:

        byte[] imageBt = null;
        FileStream fstream = new FileStream(this.txtPath.Text, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fstream);
        imageBt = br.ReadBytes((int)fstream.Length);

        string connString = "SERVER=//; Database=//; Uid=//; Pwd=//;";
        string Query = "insert cadastro.tbproduto(nomeProduto,quantProduto,precoProduto,imagemProduto) values ('" + this.txt1.Text + "','" + this.txt2.Text + "','" + this.txt3.Text + "',@IMG);";
        MySqlConnection conDataBase = new MySqlConnection(connString);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;


            conDataBase.Open();
            cmdDataBase.Parameters.Add(new MySqlParameter("@IMG",imageBt));
            myReader = cmdDataBase.ExecuteReader();
            MessageBox.Show("Salvos com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            while (myReader.Read())
            {

            }  

Here is the code for the comboBox:

        string connString = "SERVER=//; Database=//; Uid=//; Pwd=//;";
        string Query = "select * from cadastro.tbproduto where nomeProduto = '" +              comboBox1.Text + "';";
        MySqlConnection conDataBase = new MySqlConnection(connString);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;


            conDataBase.Open();

            myReader = cmdDataBase.ExecuteReader();

            while (myReader.Read())
            {
                string sName = myReader.GetString("nomeProduto");
                string qName = myReader.GetString("quantProduto");
                string pName = myReader.GetString("precoProduto");


                txt1.Text = sName;
                txt2.Text = qName;
                txt3.Text = pName;

                byte[] imgg = (byte[])(myReader["imagemProduto"]);

                    MemoryStream mstream = new MemoryStream(imgg);
                    pictureBox1.Image = System.Drawing.Image.FromStream(mstream);

            }  
    
asked by anonymous 12.12.2014 / 21:01

0 answers