private void button8_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog sd = new SaveFileDialog();
sd.Filter = "Excel File (.xls)|*.xls";
sd.Title = "Save File";
sd.AddExtension = true;
sd.ShowDialog();
if (sd.FileName != "")
{
OleDbConnection data = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +Wr u want save path + ";Extended Properties='Excel 8.0;HDR=Yes'");
data.Open();
try
{
OleDbCommand cmd = new OleDbCommand("CREATE TABLE [Sheet1] ( [c1] string, [c2] string)", data);
cmd.ExecuteNonQuery();
for (int i = 0; i < yourDataset.tables[0].rows.count; i++)
{
cmd = new OleDbCommand("INSERT INTO [Sheet1] ( [c1], [c2])Values(yourDataset.tables[0].rows[i].ittemarray[0].tostring() + "','" +yourDataset.tables[0].rows[i].ittemarray[1].tostring()+ "')", data);
cmd.ExecuteNonQuery();
}
}
catch
{
}
finally
{
data.Close();
}
}
}