C#将EXCEL导入datagridview找不到isam?请问错在哪里?

2024-12-04 21:38:12
推荐回答(2个)
回答1:

public DataSet GetList(string filePath){
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + filePath + ";Extended Properties='Excel 11.0;HDR=NO;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter mycmd = null;
DataSet ds = null;
strExcel = "select *from [sheet1$]";
mycmd = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
mycmd.Fill(ds, "table1");
return ds;
}

protected void Page_Load(object sender, EventArgs e)
{
datagridview.datasource=GetList("excel.xls");
datagridview.databind();
}

是不是这样的。。。。

回答2:

d