I want to Copy Data from Access database File to Excel worksheet. I use OLEDBConnection but I don't know how to copy all data from Access table to paste to cells A2 on excel.
My table's name is Beam Forces, It has 10 columns: Story,Beam, CaseCombo, Station, P, V2, V3, T, M2, M3.
I do not know where it is wrong. Here is my code:
private void btnInput_Click(object sender, RibbonControlEventArgs e)
{
OpenFileDialog MDB = new OpenFileDialog();
string sFile;
MDB.Filter = "Access files|*.mdb";
MDB.AddExtension = true;
MDB.CheckPathExists = true;
MDB.Title = "Choose Your Input File";
if (MDB.ShowDialog() == DialogResult.OK)
{
sFile = MDB.FileName;
try
{
OleDbConnection MyConnection = new OleDbConnection();
OleDbCommand MyCommand = new OleDbCommand();
MyConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sFile);
MyConnection.Open();
MessageBox.Show("Mở kết nối thành công");
string mySQL = "SELECT [Story],[Beam], [CaseCombo], [Station], P, V2, V3, T, M2, M3 " + "From [Beam Forces]";
OleDbCommand cmd = new OleDbCommand(mySQL, MyConnection);
MessageBox.Show(mySQL);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dtb = new DataTable();
WorkSheet curSheet = Globals.ThisAddIn.Application.ActiveSheet;
????????????????????????
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error: "+ ex);
}
}
What I have tried:
I tried to search some help from MSDN but I can't.