我想使用此代码将Excel 2010中的数据导入datagridview,但是没有显示任何结果?我该怎么办?
private void btn_calHazine_Click(object sender, EventArgs e)
{
try
{
// String name = "Items";
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
@"C:\Users\Mohsen\Desktop\Book1.xlsx" +
";Extended Properties='Excel 14.0;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [ Sheet1$]", con);
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
DataTable data = new DataTable();
sda.Fill(data);
dgv_sabadkharid.DataSource = data;
}
catch { }
}