@Topic,我在WPF中有一个程序,它将数据从MySQL数据库显示到DataGrid。一切都很好,但我想添加一个“导出”按钮,以便用户可以将查询结果导出到Excel文件。
这是我用来显示数据的代码:
if (connecToDB.openConnection() == true)
{
try
{
DataTable table = new DataTable();
string query = @"SELECT * FROM faculty_assignment WHERE faculty_id = @num";
MySqlDataAdapter sqlAdapter = new MySqlDataAdapter();
MySqlCommand start_query = new MySqlCommand(query, connecToDB.connection);
start_query.Parameters.AddWithValue("@num", facultyNum);
sqlAdapter.SelectCommand = start_query;
sqlAdapter.Fill(table);
facultyView.ItemsSource = table.DefaultView;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
我想添加的是“导出”按钮。有人知道如何编码吗?