With the below code I have loaded datagrid
in WPF from ms access DB using c# but not sure how to export the same datagrid
to Excel.
try
{
OleDbConnection connect = new OleDbConnection();
connect.ConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=|DataDirectory|\Electricalcircuits.mdb";
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from REPORT";
cmd.Connection = connect;
connect.Open();
System.Data.DataTable dt = new System.Data.DataTable();
OleDbDataAdapter DA = new OleDbDataAdapter(cmd);
DA.Fill(dt);
DG1.ItemsSource = dt.AsDataView();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.ToString());
}