ACCESS DATABASE 2007-2016 OLEOBJECT ERROR

Anonim
2023-09-01T10:12:20+00:00

I **** unable to display a binary-saved image file in a form or report. I've tried using image controls, but they didn't work at all. When I click on the Ole Object in the form section, it gives me an 'Problem while Access was communicating with OLE server or ActiveX control' error.
And this is my Windows form app:

namespace foto

{

    public partial class Form1 : Form

    {

        private OleDbConnection conn;

        public Form1()

        {

            InitializeComponent();

            // Access veritabanı bağlantısını burada ayarlayın

            string databasePath = @"C:\Users\BİLGİ_İSLEM\Source\Repos\foto\foto\deneme.accdb";

            string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + databasePath;

            conn = new OleDbConnection(connectionString);

        }

        private void ValueClear()

        {

            // Gerekirse kontrol değerlerini temizle

            PicBox.Image = null;

        }

        private void SaveButton_Click(object sender, EventArgs e)

        {

            try

            {

                // Resmi al

                Image image = PicBox.Image;

                // Veritabanı bağlantısını aç

                conn.Open();

                // SQL sorgusu ve parametreleri oluşturun

                string sql = "INSERT INTO Picture (PictureData) VALUES (?)";

                OleDbCommand PicSave = new OleDbCommand(sql, conn);

                OleDbParameter param = new OleDbParameter("@PictureData", OleDbType.LongVarBinary);

                param.Value = ImageToByteArray(image);

                PicSave.Parameters.Add(param);

                // Sorguyu çalıştır

                int rowsAffected = PicSave.ExecuteNonQuery();

                // Sonucu kontrol et

                if (rowsAffected > 0)

                {

                    MessageBox.Show("Kayıt Kaydedildi", "Bilgi");

                    ValueClear();

                }

                else

                {

                    MessageBox.Show("Kayıt Kaydedilemedi", "Hata Mesajı");

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show("Hata: " + ex.Message, "Hata Mesajı");

            }

            finally

            {

                // Veritabanı bağlantısını kapat

                conn.Close();

            }

        }

        private byte[] ImageToByteArray(Image image)

        {

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())

            {

                image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); // Resmi istediğiniz formata göre değiştirin

                return stream.ToArray();

            }

        }

        private void button1_Click(object sender, EventArgs e)

        {

            // Resim seçme işlemi için bir OpenFileDialog oluşturun

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Resim Dosyaları (*.jpg;*.png;*.gif;*.bmp)|*.jpg;*.png;*.gif;*.bmp|Tüm Dosyalar (*.*)|*.*";

            if (openFileDialog.ShowDialog() == DialogResult.OK)

            {

                // Kullanıcı bir resim dosyası seçtiğinde

                // Seçilen resmi yükle

                string selectedImagePath = openFileDialog.FileName;

                Image selectedImage = new Bitmap(selectedImagePath);

                // Yüklenen resmi PictureBox içinde göster

                PicBox.Image = selectedImage;

            }

        }

    }

}
Microsoft 365 ve Office | Access | Diğer | Windows

Kilitli Soru. Bu soru Microsoft Destek Topluluğu’ndan aktarıldı. Yararlı olup olmadığını belirtmek için oy verebilirsiniz ancak yorum veya yanıt ekleyemez ya da soruyu takip edemezsiniz.

0 yorum Açıklama yok

1 yanıt

Sıralama ölçütü: En yararlı
  1. Anonim
    2023-09-01T10:59:52+00:00

    Hello

    I’m Adeyemi and I’d be happy to help you with your question.

    It seems that you are having trouble displaying a binary-saved image file in a form or report in an Access database. The error message you mentioned, "Problem while Access was communicating with OLE server or ActiveX control," suggests that there may be an issue with the OLE server or ActiveX control that is being used to display the image.

    One possible cause of this issue could be that the OLE server or ActiveX control is not properly registered or compatible with the version of Access you are using. You may want to try re-registering the OLE server or ActiveX control, or checking if there is a newer version available that is compatible with your version of Access https://learn.microsoft.com/en-us/office/troubleshoot/access/cannot-use-odbc-or-oledb.

    Another possible cause of this issue could be related to the way the image data is being stored and retrieved from the database. You may want to check if the data type of the field storing the image data is appropriate, and if the code used to retrieve and display the image data is correct.

    I hope this information helps!

    Give back to the Community. Help the next person who has this issue by indicating if this reply solved your problem. Click Yes or No below

    Regards Adeyemi

    Bu yanıt yardımcı oldu mu?

    0 yorum Açıklama yok