zoukankan      html  css  js  c++  java
  • Excel导入数据库

    public static DataSet LoadDataFromExcel(string filePath) 
            { 
                try 
                { 
                    string strConn; 
                    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'"; 
                    OleDbConnection OleConn = new OleDbConnection(strConn); 
                    OleConn.Open(); 
                    String sql = "SELECT * FROM  [Sheet1$]";//可是更改Sheet名称,比如sheet2,等等 
    
                    OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn); 
                    DataSet OleDsExcle = new DataSet(); 
                    OleDaExcel.Fill(OleDsExcle, "Sheet1"); 
                    OleConn.Close(); 
                    return OleDsExcle; 
                } 
                catch (Exception err) 
                { 
                    MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息", 
                        MessageBoxButtons.OK, MessageBoxIcon.Information); 
                    return null; 
                } 
            }
  • 相关阅读:
    python变量和作用域
    模块
    装饰器
    转git取消commit
    RTP
    ffmpeg编译
    win7开启wifi
    LIVE555
    【FFmpeg】ffplay播放rtsp视频流花屏问题
    Windows下编译SDL
  • 原文地址:https://www.cnblogs.com/fhuafeng/p/2333812.html
Copyright © 2011-2022 走看看