当我尝试从excel导入数据时,DataGridView
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;
答案 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;