您的位置:首页 > 其它

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

2005-05-18 00:52 344 查看
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: