读入Excel中的数据到DataSet
来源:互联网 发布:网上买书的软件 编辑:程序博客网 时间:2024/05/16 17:36
public static DataSet LoadDataFromExcel(string filePath, string sheetName) { string strConn; strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [" + sheetName + "$]", strConn); DataSet myDataSet = new DataSet(); try { myCommand.Fill(myDataSet); } catch (Exception err) { MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return null; } return myDataSet; }
以上这段代码适用于Excel2007及2010,如果是2003,则需要吧Provider=Microsoft.ACE.OLEDB.12.0改为Provider=Microsoft.Jet.OLEDB.4.0。
- 读入Excel中的数据到DataSet
- dataset读取excel中的数据到打dataset中
- Excel读入dataset数据丢失问题
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到Gridview中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- 把Excel文件中的数据读入到DataGrid中
- C++内联函数(Inline)介绍
- 使用Easy_install 安装python站点包
- Python : 计算大文件MD5值
- 使用QT CREATOR2.4.1创建工程,并在LINUX上运行,能编译,GDB+GDBSERVER调试(例子工程,dvrgui)
- 十万个为什么(一)
- 读入Excel中的数据到DataSet
- CGI 环境变量
- vm虚拟机查看本机文件夹
- php框架PATH_INFO模式配置
- Spring的事务配置
- svn新建分支
- Struts 2 学习笔记 - 1.环境和文件配置
- 十万个为什么(二)
- ASP.NET中文乱码问题解决