【发布时间】:2020-03-30 23:50:48
【问题描述】:
我正在尝试将特定的 excel 文件读入我的名为 stats_table 的数据网格视图中,但大多数情况下整个系统崩溃或根本没有做任何事情。我在特定按钮下使用的导入代码如下:
private void Predict_Click(object sender, EventArgs e)
{
string path = @"C:\Users\epifa\Desktop\Master\2nd semester\esports\all_cards.xlsx";
string constr = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = "+ path + " Extended Properties=\"Excel 12.0 Macro; HDR = YES";
OleDbConnection con = new OleDbConnection(constr);
DataTable dt = new DataTable();
Stats_table.DataSource = dt;
}
你能建议吗?
【问题讨论】:
-
尝试以下操作:字符串路径 = @"C:\Users\epifa\Desktop\Master\2nd 学期\esports\all_cards.xlsx"; string constr = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = "+ path + " Extended Properties=\"Excel 12.0 Macro; HDR = YES"; OleDbConnection con = new OleDbConnection(constr); string commandText = "Select * From Sheet1"; OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, con); DataTable dt = new DataTable(); adapter.Fill(dt); Stats_table.DataSource = dt;
-
你是真的想给你的
Stats_table一个空的数据表作为数据源,还是这只是一个伪命题?你在填写数据表吗?
标签: c# datagridview