从Excel导入后,DataGridView中缺少数据

时间:2016-07-22 08:07:56

标签: c# .net

当我尝试从excel导入数据时,DataGridView

中缺少我的Excel工作表的某些数据
string pathcpnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";

OleDbConnection con = new OleDbConnection(pathcpnn);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from[" + textBox2.Text + "$]", con);

 myDataAdapter.Fill(dt);

DAtagridview1.datasource=dt;

excel sheet

Data GridView

1 个答案:

答案 0 :(得分:0)

string pathcpnn =“Provider = Microsoft.Jet.OLEDB.4.0; Data Source =”+ textBox1.Text +“; Extended Properties = \”“Excel 8.0; HDR = Yes; IMEX = 1;”;“; < / p>

OleDbConnection con = new OleDbConnection(pathcpnn);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(“Select * from [”+ textBox2.Text +“$]”,con);

myDataAdapter.Fill(DT);

DAtagridview1.datasource = DT;