您的位置:首页 > 其它

excel to DataSet

2015-11-19 08:55 309 查看
private DataSet ExcelToDS(string path, string sheetName)
{
DataSet ds = new DataSet();
try
{
string strConn = " Provider=Microsoft.Jet.OLEDB.4.0; " + " Data Source= " + path + " ; " + " Extended Properties=Excel 8.0; ";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter myCommand = null;
strExcel = string.Format(" select * from [{0}$] ", sheetName);
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, sheetName);
if (conn != null)
{
conn.Close();
myCommand.Dispose();
}
}
catch (Exception)
{
//Undo
}
return ds;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: