Ошибка передачи картинки в БД

пытаюсь передать картинку в БД mysql и возникла такая проблема, когда передаю картинку у меня возникают ошибки которые я не могу исправить или понять что не так.

У меня есть БД и поле для хранения картинок. Когда я передаю её в БД у меня передаётся не бинарный формат, а один и тот же и не верный (Скриншот 1). Если перевести с HEX то передаётся (System.Byte[])

Вот мой код:

public:
        DataBaseUniDor^ dataBaseUniDor = gcnew DataBaseUniDor();
        array<System::Byte>^ image;

    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) 
    {
        dataBaseUniDor->openConnection();

        auto studentСode = textBoxStudentСode->Text;
        auto studentSurname = textBoxStudentSurname->Text;
        auto studentName = textBoxStudentName->Text;
        auto studentPatronymic = textBoxStudentPatronymic->Text;
        auto studentGender = textBoxStudentGender->Text;
        auto studentPassport = textBoxStudentPassport->Text;
        auto studentDateBirth = textBoxStudentDateBirth->Text;
        auto studentFaculty = textBoxStudentFaculty->Text;
        auto studentGroup = textBoxStudentGroup->Text;
        auto studentHomeAddress = textBoxStudentHomeAddress->Text;
        auto studentMobilePhone = textBoxStudentMobilePhone->Text;
        auto dormitoryNumber = textBoxDormitoryNumber->Text;
        auto roomNumber = textBoxRoomNumber->Text;
        auto settlementsDate = textBoxSettlementsDate->Text;
        auto evictionsDate = textBoxEvictionsDate->Text;

        auto addQuery = "insert into UniversityDormitories(studentСode, studentSurname, studentName, studentPatronymic, " +
            "studentGender, studentPassport, studentDateBirth, studentFaculty, studentGroup, studentHomeAddress, " +
            "studentMobilePhone, dormitoryNumber, roomNumber, settlementsDate, evictionsDate, imageByte)";

        addQuery = addQuery + "values ('" + studentСode + "', " +
            "'" + studentSurname + "', " +
            "'" + studentName + "', " +
            "'" + studentPatronymic + "', " +
            "'" + studentGender + "', " +
            "'" + studentPassport + "', " +
            "'" + studentDateBirth + "', " +
            "'" + studentFaculty + "', " +
            "'" + studentGroup + "', " +
            "'" + studentHomeAddress + "', " +
            "'" + studentMobilePhone + "', " +
            "'" + dormitoryNumber + "', " +
            "'" + roomNumber + "', " +
            "'" + settlementsDate + "', " +
            "'" + evictionsDate + "', " +
            "'" + image +"')";

        auto command = gcnew SqlCommand(addQuery, dataBaseUniDor->getConnection());
        command->ExecuteNonQuery();
        
        MessageBox::Show("Запись успешно создана!","Выполнено.");
    }

    private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) 
    {
        String^ imgLoc = "";
        OpenFileDialog^ dialog = gcnew OpenFileDialog;
        dialog->Filter = "Image Files (*.BMP; *.JPG; *.PNG;)|*.BMP; *.JPG; *.PNG;|All files(*.*)|*.*";
        dialog->InitialDirectory = "C:\\Users\\selyu\\source\\repos\\DataBaseAksenov\\image";
        dialog->Title = "Выбор фото";
        if (dialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
        {
            imgLoc = "" + dialog->FileName;
            pictureBox1->ImageLocation = imgLoc;
        }
        FileStream^ fileStreamIMG = gcnew FileStream(imgLoc, FileMode::Open, FileAccess::Read);
        BinaryReader^ binaryReaderIMG = gcnew BinaryReader(fileStreamIMG);
        image = binaryReaderIMG->ReadBytes((int)fileStreamIMG->Length);
    }

После чего когда пытаюсь вывести картинку из БД в программе получаю ошибку (Скриншот 2.) Вот участок этого кода:

void imageDisplay()
        {
            String^ imageString = "SELECT imageByte FROM UniversityDormitories WHERE id=" + textBoxID->Text + "";
            SqlCommand^ command = gcnew SqlCommand(imageString, dataBase->getConnection());
            dataBase->openConnection();

            SqlDataReader^ reader = command->ExecuteReader();
            reader->Read();

            if (reader->HasRows)
            {
                array<System::Byte>^ image = (array<System::Byte>^)(reader[0]);
                MemoryStream^ memoryStream = gcnew MemoryStream(image);
                pictureBox1->Image = Image::FromStream(memoryStream);
            }
        }

Скриншот 1 Скриншот 2


Ответы (0 шт):