Hi @Paranthaman ,
I am using Access db engine 2010, and after slightly modifying part of the code, clicking button1 repeatedly will not report an error.
I suggest you to refer to the code:
private:
System::Void MyForm_Load(System::Object^ sender,
System::EventArgs^ e) {
DataTable^ MyDataTable = gcnew DataTable();
String^ MyExcelFile = "E:\\Test.xlsx";
String^ MyStrConn =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
MyExcelFile +
"; Extended Properties=\"Excel 12.0; HDR=YES; OLE DB "
"Services=-1; \"";
String^ MyExcelSheet = "[Sheet1$]";
String^ MySQLSelect = "select * from " + MyExcelSheet;
System::Data::OleDb::OleDbConnection^ Cn1 = nullptr;
Cn1 = gcnew System::Data::OleDb::OleDbConnection(MyStrConn);
System::Data::OleDb::OleDbCommand^ MyCmd = nullptr;
MyCmd =
gcnew System::Data::OleDb::OleDbCommand(MySQLSelect, Cn1);
Cn1->Open();
System::Data::OleDb::OleDbDataAdapter^ Da1 =
gcnew System::Data::OleDb::OleDbDataAdapter(MyCmd);
Da1->Fill(MyDataTable);
Cn1->Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
MyForm2^ MyStForm =gcnew MyForm2();
MyStForm->MdiParent = this->MdiParent;
MyStForm->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
MyStForm->Dock = DockStyle::Fill;
MyStForm->Show();
}
Best regards,
Elya
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.