C#将EXCEL导入datagridview找不到isam?请问错在哪里?
stringstrConn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+filePath+";ExtendedPrope...
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");
DataTable tb = new System.Data.DataTable(); 展开
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");
DataTable tb = new System.Data.DataTable(); 展开
2个回答
展开全部
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();
}
是不是这样的。。。。
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();
}
是不是这样的。。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询