从Excel导出数据,绑定DataGrid的方法

string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath("products.xls"+ ";Extended Properties=Excel 8.0"
            OleDbConnection conn 
= new OleDbConnection(strConn);
            OleDbDataAdapter adp 
= new OleDbDataAdapter("Select * from [Sheet1$]",conn);//Sheet1是Excel的名称
            DataSet ds = new DataSet();
            adp.Fill(ds,
"Products");
            ExlDataGrid.DataSource 
= ds.Tables["Products"].DefaultView;
            ExlDataGrid.DataBind();

posted on 2005-05-18 00:52  黎宇  阅读(396)  评论(0编辑  收藏  举报

导航