Attempted to read or write protected memory. When I call showDialog method of openfileDialog

前端 未结 3 443
北海茫月
北海茫月 2020-12-06 15:07

recently in my project when I call ShowDialog method of OpenFileDialog I get this error:

\"Attempted to read or write protected memory. Thi

3条回答
  •  时光取名叫无心
    2020-12-06 15:39

    I had this problem too.

    I was using OpenFileDialog to select an Excel file, then read the data with .net Oledb and write data to Access database.

    The first time: OK

    The second time, after select file, appeared this message: Attempted to read or write protected memory

    My solution:

    A form "A" with an OpenFileDialog and a button to display and select files and: openFileDialog1.ReadOnlyChecked = true; openFileDialog1.ShowReadOnly = true;

    A form "B" With a get/set to set the filename to read A method to read excel file and write to Access db.

    From "A", send filename to read to "B" form Load "B" form, execute the main process, view results and close form On return "A", I could select another file and repeat the process without errors

    No more "Attempted to read or write protected memory" error

    I don't know if it's the best solution but the application runs well.

    Greetings

提交回复
热议问题